[GNC-dev] util/gnc-vcs-info fails if building from a Git worktree (with possible solution)

Kevin Buckley <[email protected]>
Newsgroups gmane.comp.gnome.apps.gnucash.devel
Message-ID <CAKJd7RODX=OfGAqBZLyN5m6+tJ2w03GaN_ev_G1N7TrBnfXJkA@mail.gmail.com>
I have recently discovered that

util/gnc-vcs-info

fails if building from a Git worktree.

Within gnc-vcs-info is this test

# Maybe it's git?
real_gitdir="${real_srcdir}"/.git
if test -d "${real_gitdir}"
then
  ...

however, if you have checked out a Git branch into a worktree,
then .git will be a file containing the string

gitdir: /path/to/main/working/tree/.git/worktrees/branchname

In order to allow gnc-vcs-info to "do the right thing" from
within a Git worktree, I'd suggest adding the following stanza
to gnc-vcs-info, which basically replicates the code from the
existing "Maybe it's git?" block, but allows for the fact that
you know it's a worktree

   fi
 fi

+# Maybe it's a git worktree?
+real_gitdir="${real_srcdir}"/.git
+if test -f "${real_gitdir}"
+then
+  worktrees=`grep worktrees ${real_gitdir}`
+  if test $? = 0 ; then
+
+    if [ "$request" = "type" ]
+    then
+      echo "git"
+      exit 0
+    fi
+
+    # The windows build uses environment variable $GIT_CMD to invoke
git (adding git
+    # to the PATH in Windows results in a build failure).
+    # So for platform independence, use GIT_CMD for all
+    [ -n "$GIT_CMD" ] || GIT_CMD=git
+    if [ "$request" = "date" ]
+    then
+      exec "$GIT_CMD" log -1 --format=%cd --date=short
+      exit 0
+    fi
+
+    githead=`"$GIT_CMD" log -1 --pretty=format:"%h" HEAD 2>/dev/null`
 # short hash only
+    if test $? = 0 ; then
+      /bin/echo -n $githead
+      # Add a "+" to the hash if there deleted or modified files (not
excluded by .gitignore and friends)
+      # "Ignores" untracked files
+      # [ $("$GIT_CMD" ls-files -dkm 2>/dev/null | wc -l) -gt 0 ] &&
/bin/echo -n "+"
+      # Includes untracked files
+      [ $("$GIT_CMD" ls-files -dkmo --exclude-standard 2>/dev/null |
wc -l) -gt 0 ] && /bin/echo -n "+"
+      echo
+      exit 0
+    else
      exit 1
+    fi
+
+  fi
+fi
+
 if test -d "${real_srcdir}"/.bzr ;
 then
   # If we're only interested in the vcs type, then we're done here


or you might want to come up with something else to handle building
from a Git Worktree, in which case feel free to (ab)use the above as
you see fir.

HTH someone who tries to do what I was, when I discovered this
Kevin Buckley
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.