]> git.ipfire.org Git - thirdparty/git.git/commitdiff
git-gui: fix use of GIT_CEILING_DIRECTORIES
authorPatrick Steinhardt <ps@pks.im>
Tue, 10 Feb 2026 12:45:17 +0000 (13:45 +0100)
committerPatrick Steinhardt <ps@pks.im>
Tue, 17 Feb 2026 05:58:00 +0000 (06:58 +0100)
The GIT-VERSION-GEN script sets up GIT_CEILING_DIRECTORIES so that we
won't accidentally parse version information from an unrelated parent
repository. The ceiling is derived from the source directory by simply
appendign "/.." to it, which mean that we'll only consider the current
directory for repository discovery.

This works alright in the case where git-gui is built as a standalone
project, but it breaks when git-gui is embedded into a _related_ parent
project. This is for example how git-gui is distributed via Git.

Interestingly enough, the version information is still derived properly
when building git-gui via Git's Makefile. In that case we eventually end
up specifying the ceiling directory as "./.." as we use relative paths
there, and that seems to not restrict the repository discovery.

But when building via Meson we specify the source directory as an
absolute path, and if so the repository discovery _is_ stopped. The
consequence is that we won't be able to derive the version in that case.

Fix the issue by adding a new optional parameter to GIT-VERSION-GEN that
allows the caller to override the parent project directory and wire up
new build options for Meson and Make that allows users to specify it.

Note that by default we won't set the parent project directory. This
isn't required for Meson anyway as we already use absolute paths there,
but for our Makefile it means that we still end up with "./.." as
ceiling directory, which is ineffective. But using e.g. pwd(1) as the
default value would break downstream's version generation, unless we
updated git-gui and the Makefile at the same point in time.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
GIT-VERSION-GEN
Makefile
meson.build
meson_options.txt [new file with mode: 0644]

index c2767b4136cbbf85fa2c70a558030d7fd47c176a..2f729de4bb55844405b619fcb821fd894ecb34fb 100755 (executable)
@@ -5,19 +5,27 @@ DEF_VER=0.21.GITGUI
 LF='
 '
 
-if test "$#" -ne 2
+if test "$#" -lt 2
 then
-       echo >&2 "usage: $0 <SOURCE_DIR> <OUTPUT>"
+       echo >&2 "usage: $0 <SOURCE_DIR> <OUTPUT> [<PARENT_PROJECT_DIR>]"
        exit 1
 fi
 
 SOURCE_DIR="$1"
 OUTPUT="$2"
+PARENT_PROJECT_DIR="$3"
 
 # Protect us from reading Git version information outside of the Git directory
 # in case it is not a repository itself, but embedded in an unrelated
-# repository.
-GIT_CEILING_DIRECTORIES="$SOURCE_DIR/.."
+# repository. The PARENT_PROJECT_DIR variable can be used to override this, for
+# example when git-gui is included as a subproject.
+if test -n "$PARENT_PROJECT_DIR"
+then
+       GIT_CEILING_DIRECTORIES="$PARENT_PROJECT_DIR/.."
+else
+       GIT_CEILING_DIRECTORIES="$SOURCE_DIR/.."
+fi
+
 export GIT_CEILING_DIRECTORIES
 
 tree_search ()
index 69b0b844352bc1854e74a80a9312f8e4a331fbd6..5679af62bdc0cc3cc9a56622ee026deeac32c6f1 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -9,7 +9,7 @@ all::
 #
 
 GIT-VERSION-FILE: FORCE
-       @$(SHELL_PATH) ./GIT-VERSION-GEN . $@
+       @$(SHELL_PATH) ./GIT-VERSION-GEN . $@ "$(PARENT_PROJECT_DIR)"
 
 uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
 uname_R := $(shell sh -c 'uname -r 2>/dev/null || echo not')
index 320ba09ecfeb32188dfbce718d288c2bca0a5013..4a604657531e34d7bd82bc52f1a14508232f3ad2 100644 (file)
@@ -34,6 +34,7 @@ version_file = custom_target(
     '@INPUT@',
     meson.current_source_dir(),
     '@OUTPUT@',
+    get_option('parent_project_dir'),
   ],
   build_always_stale: true,
 )
diff --git a/meson_options.txt b/meson_options.txt
new file mode 100644 (file)
index 0000000..7591a34
--- /dev/null
@@ -0,0 +1,2 @@
+option('parent_project_dir', type: 'string', value: '',
+  description: 'The directory of the parent project. This is used so that the version can be determined even in case git-gui is included as a subtree.')