Skip to content

Commit

Permalink
Fixed bash-completion integration with git
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
spog authored and admorgan committed Jul 22, 2024
1 parent 5453dff commit 7816a57
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 28 deletions.
29 changes: 18 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
SHELL := bash
INSTALL ?= install

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

# Install variables:
PREFIX ?= /usr/local
INSTALL_LIB ?= $(DESTDIR)$(shell git --exec-path)
INSTALL_BIN ?= $(PREFIX)/bin
INSTALL_LIB ?= $(PREFIX)/share/$(NAME)
INSTALL_EXT ?= $(INSTALL_LIB)/$(NAME).d
INSTALL_MAN1 ?= $(DESTDIR)$(PREFIX)/share/man/man1
INSTALL_MAN1 ?= $(PREFIX)/share/man/man1
LINK_REL_DIR := $(shell realpath --relative-to=$(INSTALL_BIN) $(INSTALL_LIB))

# Docker variables:
DOCKER_TAG ?= 0.0.6
Expand Down Expand Up @@ -60,18 +63,22 @@ $(DOCKER_TESTS):

# Install support:
install:
install -d -m 0755 $(INSTALL_LIB)/
install -C -m 0755 $(LIB) $(INSTALL_LIB)/
install -d -m 0755 $(INSTALL_EXT)/
install -C -m 0644 $(EXTS) $(INSTALL_EXT)/
install -d -m 0755 $(INSTALL_MAN1)/
install -C -m 0644 $(MAN1)/$(NAME).1 $(INSTALL_MAN1)/
$(INSTALL) -d -m 0755 $(DESTDIR)$(INSTALL_LIB)/
$(INSTALL) -C -m 0755 $(LIB) $(DESTDIR)$(INSTALL_LIB)/
sed -i 's!^SUBREPO_EXT_DIR=.*!SUBREPO_EXT_DIR=$(INSTALL_EXT)!' $(DESTDIR)$(INSTALL_LIB)/$(NAME)
$(INSTALL) -d -m 0755 $(DESTDIR)$(INSTALL_BIN)
ln -s $(LINK_REL_DIR)/$(NAME) $(DESTDIR)$(INSTALL_BIN)/$(NAME)
$(INSTALL) -d -m 0755 $(DESTDIR)$(INSTALL_EXT)/
$(INSTALL) -C -m 0644 $(EXTS) $(DESTDIR)$(INSTALL_EXT)/
$(INSTALL) -d -m 0755 $(DESTDIR)$(INSTALL_MAN1)/
$(INSTALL) -C -m 0644 $(MAN1)/$(NAME).1 $(DESTDIR)$(INSTALL_MAN1)/

# Uninstall support:
uninstall:
rm -f $(INSTALL_LIB)/$(NAME)
rm -fr $(INSTALL_EXT)
rm -f $(INSTALL_MAN1)/$(NAME).1
rm -f $(DESTDIR)$(INSTALL_BIN)/$(NAME)
rm -fr $(DESTDIR)$(INSTALL_EXT)
rm -fr $(DESTDIR)$(INSTALL_LIB)
rm -f $(DESTDIR)$(INSTALL_MAN1)/$(NAME).1

env:
@echo "export PATH=\"$$PWD/lib:\$$PATH\""
Expand Down
21 changes: 4 additions & 17 deletions lib/git-subrepo
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,8 @@ set -e
export FILTER_BRANCH_SQUELCH_WARNING=1

# Import Bash+ helper functions:
SOURCE=${BASH_SOURCE[0]}
while [[ -h $SOURCE ]]; do
DIR=$( cd -P "$( dirname "$SOURCE" )" && pwd )
SOURCE=$(readlink "$SOURCE")
[[ $SOURCE != /* ]] && SOURCE=$DIR/$SOURCE
done
SOURCE_DIR=$(dirname "$SOURCE")

if [[ -z $GIT_SUBREPO_ROOT ]]; then
# If `make install` installation used:
source "${SOURCE_DIR}/git-subrepo.d/bash+.bash"
else
# If `source .rc` method used:
source "${SOURCE_DIR}/../ext/bashplus/lib/bash+.bash"
fi
SUBREPO_EXT_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]}")")/git-subrepo.d" # replaced by `make install`
source "${SUBREPO_EXT_DIR}/bash+.bash"
bash+:import :std can version-check


Expand Down Expand Up @@ -397,7 +384,7 @@ command:config() {

# Launch the manpage viewer:
command:help() {
source "${SOURCE_DIR}/git-subrepo.d/help-functions.bash"
source "${SUBREPO_EXT_DIR}/help-functions.bash"
local cmd=${command_arguments[0]}
if [[ $cmd ]]; then
if can "help:$cmd"; then
Expand Down Expand Up @@ -1987,7 +1974,7 @@ OK() {
usage-error() {
local msg="git-subrepo: $1" usage=
if [[ $GIT_SUBREPO_TEST_ERRORS != true ]]; then
source "${SOURCE_DIR}/git-subrepo.d/help-functions.bash"
source "${SUBREPO_EXT_DIR}/help-functions.bash"
if can "help:$command"; then
msg=$'\n'"$msg"$'\n'"$("help:$command")"$'\n'
fi
Expand Down

0 comments on commit 7816a57

Please sign in to comment.