aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2025-04-22 10:36:11 +0200
committerJunio C Hamano <gitster@pobox.com>2025-04-22 08:26:12 -0700
commitfe35ce2ef83b597f0e0ca9fb0f7662ce018d3443 (patch)
treef114bda8cce51ee49fc05f40c43dcb98f441bef4
parentThe seventh batch (diff)
downloadgit-fe35ce2ef83b597f0e0ca9fb0f7662ce018d3443.tar.gz
git-fe35ce2ef83b597f0e0ca9fb0f7662ce018d3443.zip
contrib/completion: install Bash completion
The shell completion scripts in "contrib/completion" are being tested, but none of our build systems support installing them. This is somewhat confusing for Meson, where users can explicitly enable building these scripts via `-Dcontrib=completion`. This option only controlls whether the completions are built and tested against, where "building" is a bit of an euphemism for "copying them into the build directory". Teach both our Makefile and Meson to install our Bash completion script. For now, this is the only completion script that we're installing given that Bash completions "just work" with a canonical well-known location nowadays. Other completion scripts, like for example the one for zsh, don't have a well-known location and/or require extra steps by the user to make them available. As such, we skip installing these scripts for now, but we may do so in the future if we ever figure out a proper way to do this. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--Makefile6
-rw-r--r--contrib/completion/meson.build18
2 files changed, 24 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index 13f9062a05..9cc275de93 100644
--- a/Makefile
+++ b/Makefile
@@ -618,6 +618,7 @@ prefix = $(HOME)
bindir = $(prefix)/bin
mandir = $(prefix)/share/man
infodir = $(prefix)/share/info
+bash_completion_dir = $(prefix)/share/bash-completion/completions
gitexecdir = libexec/git-core
mergetoolsdir = $(gitexecdir)/mergetools
sharedir = $(prefix)/share
@@ -2325,6 +2326,7 @@ bindir_relative_SQ = $(subst ','\'',$(bindir_relative))
mandir_SQ = $(subst ','\'',$(mandir))
mandir_relative_SQ = $(subst ','\'',$(mandir_relative))
infodir_relative_SQ = $(subst ','\'',$(infodir_relative))
+bash_completion_dir_SQ = $(subst ','\'',$(bash_completion_dir))
perllibdir_SQ = $(subst ','\'',$(perllibdir))
localedir_SQ = $(subst ','\'',$(localedir))
localedir_relative_SQ = $(subst ','\'',$(localedir_relative))
@@ -3569,6 +3571,10 @@ endif
ifneq (,$X)
$(foreach p,$(patsubst %$X,%,$(filter %$X,$(ALL_COMMANDS_TO_INSTALL) $(OTHER_PROGRAMS))), test '$(DESTDIR_SQ)$(gitexec_instdir_SQ)/$p' -ef '$(DESTDIR_SQ)$(gitexec_instdir_SQ)/$p$X' || $(RM) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)/$p';)
endif
+ifndef NO_BASH_COMPLETION
+ $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(bash_completion_dir_SQ)' && \
+ $(INSTALL) -m 644 contrib/completion/git-completion.bash '$(DESTDIR_SQ)$(bash_completion_dir_SQ)/git'
+endif
bindir=$$(cd '$(DESTDIR_SQ)$(bindir_SQ)' && pwd) && \
execdir=$$(cd '$(DESTDIR_SQ)$(gitexec_instdir_SQ)' && pwd) && \
diff --git a/contrib/completion/meson.build b/contrib/completion/meson.build
index 3a9ddab594..576125b083 100644
--- a/contrib/completion/meson.build
+++ b/contrib/completion/meson.build
@@ -14,3 +14,21 @@ foreach script : [
)
endif
endforeach
+
+# We have to discern between the test dependency and the installed file. Our
+# tests assume the completion scripts to have the same name as the in-tree
+# files, but the installed filenames need to match the executable's basename.
+if meson.version().version_compare('>=1.3.0')
+ fs.copyfile('git-completion.bash', 'git',
+ install: true,
+ install_dir: get_option('datadir') / 'bash-completion/completions',
+ )
+else
+ configure_file(
+ input: 'git-completion.bash',
+ output: 'git',
+ copy: true,
+ install: true,
+ install_dir: get_option('datadir') / 'bash-completion/completions',
+ )
+endif