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

john jralls at ceridwen.us
Sun Jul 10 13:00:34 EDT 2022



> On Jul 10, 2022, at 4:38 AM, Kevin Buckley <kevin.m.buckley at gmail.com> wrote:
> 
> 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.

Nice. Please submit that as a Github pull request, see https://wiki.gnucash.org/wiki/Simple_Pull_Request

Regards,
John Ralls



More information about the gnucash-devel mailing list