git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Pitfalls in auto-fast-forwarding heads that are not checked out?

From
Martin Langhoff <martin.langhoff@gmail.com>
Date
May 3, 2013, 22:46 UTC
Message-ID
<CACPiFCLnjCeCpt8wR71bFweFyA3rFCsnbEiR1yRD1n=X5K84Mw@mail.gmail.com>

I am building a small git wrapper around puppet, and one of the actions it performs is auto-fastforwarding of branches without checking them out.

In simplified code... we ensure that we are on a head called master, and in some cases "ppg commit", will commit to master and...

  ## early on
  # sanity-check we are on master
  headname=$(git rev-parse --symbolic-full-name --revs-only HEAD)
  if [ "$headname" -ne "refs/heads/headname" ]; then
      echo >&2 "ERROR: can only issue --immediate commit from the
master branch!"
      exit 1
  fi
  ## then
  git commit -bla blarg baz
  ## and then...
  # ensure we can ff
  head_sha1=$(git rev-parse --revs-only master)
  mb=$(git merge-base $production_sha1 refs/heads/master)
  if [[ "$mb" -ne "$production_sha1" ]]; then
      echo >&2 "ERROR: cannot fast-forward master to production"
      exit 1
  fi
  $GIT_EXEC_PATH/git-update-ref -m "ppg immediate commit"
refs/heads/production $head_sha1 $production_sha1 || exit 1

Are there major pitfalls in this approach? I cannot think of any, but git has stayed away from updating my local tracking branches; so maybe there's a reason for that...

cheers,
m
--
 martin.langhoff@gmail.com
 -  ask interesting questions
 - don't get distracted with shiny stuff  - working code first
 ~ http://docs.moodle.org/en/User:Martin_Langhoff
Next: Johannes Sixt
Message 1 of 6 in “Pitfalls in auto-fast-forwarding heads that are not checked out?”
  1. Martin LanghoffMay 3, 2013
  2. Johannes SixtMay 4, 2013
  3. Martin LanghoffMay 4, 2013
  4. John SzakmeisterMay 4, 2013
  5. Jonathan NiederMay 4, 2013
  6. Martin LanghoffMay 7, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.