Skip to content

Commit 7816a57

Browse files
spogadmorgan
authored andcommitted
Fixed bash-completion integration with git
Using the 'make install' method, the default 'git-core' location of git-subrepo executable does not automatically integrate git-subrepo into git's own bash-completion. This change moves git-subrepo executable with support scripts into /usr/share/git-subrepo. Then a symlink to the 'git-subrepo' executable script has been added into /usr/bin to achieve recognition of the 'git subrepo' sub-command under the git bash-completion (through git's: --list-cmds=...,other,...). Additional adjustment of Makefile and git-subrepo script were made to make Makefile more generic and to make DESTDIR usage together with potentially overriden install vars more manageable. By overriding INSTALL_LIB and INSTALL_EXT to the same path, we achieve removal of the unnecessary 'git-subrepo.d' subdirectory inside the /usr/share/git-subrepo path. Note that non 'make install' ways of installation should work as before but without the need for the GIT_SUBREPO_ROOT variable. Potentially, if 'realpath' addition in git-sibrepo change isn't available on all target systems, readlink could still be used instead.
1 parent 5453dff commit 7816a57

File tree

2 files changed

+22
-28
lines changed

2 files changed

+22
-28
lines changed

Makefile

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
SHELL := bash
2+
INSTALL ?= install
23

34
# Make sure we have git:
45
ifeq ($(shell which git),)
@@ -17,9 +18,11 @@ SHARE = share
1718

1819
# Install variables:
1920
PREFIX ?= /usr/local
20-
INSTALL_LIB ?= $(DESTDIR)$(shell git --exec-path)
21+
INSTALL_BIN ?= $(PREFIX)/bin
22+
INSTALL_LIB ?= $(PREFIX)/share/$(NAME)
2123
INSTALL_EXT ?= $(INSTALL_LIB)/$(NAME).d
22-
INSTALL_MAN1 ?= $(DESTDIR)$(PREFIX)/share/man/man1
24+
INSTALL_MAN1 ?= $(PREFIX)/share/man/man1
25+
LINK_REL_DIR := $(shell realpath --relative-to=$(INSTALL_BIN) $(INSTALL_LIB))
2326

2427
# Docker variables:
2528
DOCKER_TAG ?= 0.0.6
@@ -60,18 +63,22 @@ $(DOCKER_TESTS):
6063

6164
# Install support:
6265
install:
63-
install -d -m 0755 $(INSTALL_LIB)/
64-
install -C -m 0755 $(LIB) $(INSTALL_LIB)/
65-
install -d -m 0755 $(INSTALL_EXT)/
66-
install -C -m 0644 $(EXTS) $(INSTALL_EXT)/
67-
install -d -m 0755 $(INSTALL_MAN1)/
68-
install -C -m 0644 $(MAN1)/$(NAME).1 $(INSTALL_MAN1)/
66+
$(INSTALL) -d -m 0755 $(DESTDIR)$(INSTALL_LIB)/
67+
$(INSTALL) -C -m 0755 $(LIB) $(DESTDIR)$(INSTALL_LIB)/
68+
sed -i 's!^SUBREPO_EXT_DIR=.*!SUBREPO_EXT_DIR=$(INSTALL_EXT)!' $(DESTDIR)$(INSTALL_LIB)/$(NAME)
69+
$(INSTALL) -d -m 0755 $(DESTDIR)$(INSTALL_BIN)
70+
ln -s $(LINK_REL_DIR)/$(NAME) $(DESTDIR)$(INSTALL_BIN)/$(NAME)
71+
$(INSTALL) -d -m 0755 $(DESTDIR)$(INSTALL_EXT)/
72+
$(INSTALL) -C -m 0644 $(EXTS) $(DESTDIR)$(INSTALL_EXT)/
73+
$(INSTALL) -d -m 0755 $(DESTDIR)$(INSTALL_MAN1)/
74+
$(INSTALL) -C -m 0644 $(MAN1)/$(NAME).1 $(DESTDIR)$(INSTALL_MAN1)/
6975

7076
# Uninstall support:
7177
uninstall:
72-
rm -f $(INSTALL_LIB)/$(NAME)
73-
rm -fr $(INSTALL_EXT)
74-
rm -f $(INSTALL_MAN1)/$(NAME).1
78+
rm -f $(DESTDIR)$(INSTALL_BIN)/$(NAME)
79+
rm -fr $(DESTDIR)$(INSTALL_EXT)
80+
rm -fr $(DESTDIR)$(INSTALL_LIB)
81+
rm -f $(DESTDIR)$(INSTALL_MAN1)/$(NAME).1
7582

7683
env:
7784
@echo "export PATH=\"$$PWD/lib:\$$PATH\""

lib/git-subrepo

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,8 @@ set -e
1212
export FILTER_BRANCH_SQUELCH_WARNING=1
1313

1414
# Import Bash+ helper functions:
15-
SOURCE=${BASH_SOURCE[0]}
16-
while [[ -h $SOURCE ]]; do
17-
DIR=$( cd -P "$( dirname "$SOURCE" )" && pwd )
18-
SOURCE=$(readlink "$SOURCE")
19-
[[ $SOURCE != /* ]] && SOURCE=$DIR/$SOURCE
20-
done
21-
SOURCE_DIR=$(dirname "$SOURCE")
22-
23-
if [[ -z $GIT_SUBREPO_ROOT ]]; then
24-
# If `make install` installation used:
25-
source "${SOURCE_DIR}/git-subrepo.d/bash+.bash"
26-
else
27-
# If `source .rc` method used:
28-
source "${SOURCE_DIR}/../ext/bashplus/lib/bash+.bash"
29-
fi
15+
SUBREPO_EXT_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]}")")/git-subrepo.d" # replaced by `make install`
16+
source "${SUBREPO_EXT_DIR}/bash+.bash"
3017
bash+:import :std can version-check
3118

3219

@@ -397,7 +384,7 @@ command:config() {
397384

398385
# Launch the manpage viewer:
399386
command:help() {
400-
source "${SOURCE_DIR}/git-subrepo.d/help-functions.bash"
387+
source "${SUBREPO_EXT_DIR}/help-functions.bash"
401388
local cmd=${command_arguments[0]}
402389
if [[ $cmd ]]; then
403390
if can "help:$cmd"; then
@@ -1987,7 +1974,7 @@ OK() {
19871974
usage-error() {
19881975
local msg="git-subrepo: $1" usage=
19891976
if [[ $GIT_SUBREPO_TEST_ERRORS != true ]]; then
1990-
source "${SOURCE_DIR}/git-subrepo.d/help-functions.bash"
1977+
source "${SUBREPO_EXT_DIR}/help-functions.bash"
19911978
if can "help:$command"; then
19921979
msg=$'\n'"$msg"$'\n'"$("help:$command")"$'\n'
19931980
fi

0 commit comments

Comments
 (0)