1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
From: =?UTF-8?q?Samo=20Poga=C4=8Dnik?= <samo_pogacnik@t-2.net>
Date: Sat, 19 Oct 2024 18:55:50 +0200
Forwarded: https://github.com/ingydotnet/git-subrepo/pull/639
Subject: 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 overridden 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.
---
Makefile | 29 ++++++++++++++++++-----------
lib/git-subrepo | 21 ++++-----------------
2 files changed, 22 insertions(+), 28 deletions(-)
diff --git a/Makefile b/Makefile
index 4b028a5..8dd567f 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,5 @@
SHELL := bash
+INSTALL ?= install
# Make sure we have git:
ifeq ($(shell which git),)
@@ -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
@@ -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\""
diff --git a/lib/git-subrepo b/lib/git-subrepo
index cfeeae9..ca3c739 100755
--- a/lib/git-subrepo
+++ b/lib/git-subrepo
@@ -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
@@ -396,7 +383,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
@@ -1986,7 +1973,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
|