From ca265e0fb547e72e0ba3cde972f1cb3630bfeaaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samo=20Poga=C4=8Dnik?= Date: Fri, 25 Oct 2024 13:48:59 +0200 Subject: [PATCH 1/6] 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 4b028a5f..8dd567f4 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 546f061a..00487e4f 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 @@ -1992,7 +1979,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 From 44660beee9cbc8945d66921aadfda66f92f16d73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samo=20Poga=C4=8Dnik?= Date: Fri, 25 Oct 2024 13:51:20 +0200 Subject: [PATCH 2/6] Fixed 'make test' for debian build Initialize own git repo, if project isn't a git clone. Local git config 'autocrlf' has been removed. Local default branches were set for all test repos. Tests were adapted for all local git configurations. Run tests with fixed locale. --- test/clone.t | 2 +- test/config.t | 3 +++ test/init.t | 6 ++++++ test/issue29.t | 12 +++++++++--- test/issue95.t | 9 ++++++--- test/issue96.t | 9 ++++++--- test/push-after-init.t | 10 ++++++++-- test/setup | 23 +++++++++++++++-------- 8 files changed, 54 insertions(+), 20 deletions(-) diff --git a/test/clone.t b/test/clone.t index 14515381..4a066d7e 100644 --- a/test/clone.t +++ b/test/clone.t @@ -10,7 +10,7 @@ clone-foo-and-bar ( mkdir -p "$OWNER/empty" - git init "$OWNER/empty" + git init --initial-branch=$DEFAULTBRANCH "$OWNER/empty" ) # Test that the repos look ok: diff --git a/test/config.t b/test/config.t index ec5160c4..e06e9890 100644 --- a/test/config.t +++ b/test/config.t @@ -13,6 +13,9 @@ gitrepo=$OWNER/init/doc/.gitrepo ( cd "$OWNER/init" + git config user.email "ini@ini" + git config user.name "IniUser" + git config init.defaultBranch $DEFAULTBRANCH git subrepo init doc ) > /dev/null diff --git a/test/init.t b/test/init.t index 56453dc4..b3450a8e 100644 --- a/test/init.t +++ b/test/init.t @@ -22,6 +22,9 @@ gitrepo=$OWNER/init/doc/.gitrepo output=$( cd "$OWNER/init" + git config user.email "ini@ini" + git config user.name "IniUser" + git config init.defaultBranch $DEFAULTBRANCH git subrepo init doc ) @@ -48,6 +51,9 @@ rm -fr "$OWNER/init" git clone "$UPSTREAM/init" "$OWNER/init" &>/dev/null ( cd "$OWNER/init" + git config user.email "ini@ini" + git config user.name "IniUser" + git config init.defaultBranch $DEFAULTBRANCH git subrepo init doc -r git@github.com:user/repo -b foo -M rebase ) >/dev/null diff --git a/test/issue29.t b/test/issue29.t index 57df236e..c12684e5 100644 --- a/test/issue29.t +++ b/test/issue29.t @@ -18,14 +18,16 @@ cd "$TMP" # Make 3 new repos: ( mkdir share main1 main2 - git init share - git init main1 - git init main2 + git init --initial-branch=$DEFAULTBRANCH share + git init --initial-branch=$DEFAULTBRANCH main1 + git init --initial-branch=$DEFAULTBRANCH main2 ) > /dev/null # Add an empty 'readme' to the share repo: ( cd share + git config user.name "ShrUser" + git config user.email "shr@ma1" echo '* text eol=lf' > .gitattributes touch readme git add readme .gitattributes @@ -37,6 +39,8 @@ cd "$TMP" # `subrepo clone` the share repo into main1: ( cd main1 + git config user.name "Ma1User" + git config user.email "ma1@ma1" touch main1 git add main1 git commit -m "Initial main1" @@ -46,6 +50,8 @@ cd "$TMP" # `subrepo clone` the share repo into main2: ( cd main2 + git config user.name "Ma2User" + git config user.email "ma2@ma2" touch main2 git add main2 git commit -m "Initial main2" diff --git a/test/issue95.t b/test/issue95.t index b268fbe8..46c432dc 100644 --- a/test/issue95.t +++ b/test/issue95.t @@ -12,13 +12,15 @@ use Test::More # Make two new repos ( mkdir host sub - git init host - git init sub + git init --initial-branch=$DEFAULTBRANCH host + git init --initial-branch=$DEFAULTBRANCH sub ) > /dev/null # Initialize host repo ( cd host + git config user.name "HstUser" + git config user.email "hst@hst" touch host git add host git commit -m "host initial commit" @@ -27,7 +29,8 @@ use Test::More # Initialize sub repo ( cd sub - git init + git config user.name "SubUser" + git config user.email "sub@sub" touch subrepo git add subrepo git commit -m "subrepo initial commit" diff --git a/test/issue96.t b/test/issue96.t index 1b16567c..d1250e21 100644 --- a/test/issue96.t +++ b/test/issue96.t @@ -11,13 +11,15 @@ use Test::More # Make two new repos ( mkdir host sub - git init host - git init sub + git init --initial-branch=$DEFAULTBRANCH host + git init --initial-branch=$DEFAULTBRANCH sub ) > /dev/null # Initialize host repo ( cd host + git config user.name "HstUser" + git config user.email "hst@hst" touch host git add host git commit -m "host initial commit" @@ -26,7 +28,8 @@ use Test::More # Initialize sub repo ( cd sub - git init + git config user.name "SubUser" + git config user.email "sub@sub" touch subrepo git add subrepo git commit -m "subrepo initial commit" diff --git a/test/push-after-init.t b/test/push-after-init.t index f0be2edd..e7bda8d4 100644 --- a/test/push-after-init.t +++ b/test/push-after-init.t @@ -12,12 +12,18 @@ use Test::More ( mkdir -p "$OWNER/init" cd "$OWNER/init" - git init + git init --initial-branch=$DEFAULTBRANCH + git config user.name "IniUser" + git config user.email "ini@ini" mkdir doc add-new-files doc/FooBar git subrepo init doc || die mkdir ../upstream - git init --bare ../upstream || die + git init --initial-branch=$DEFAULTBRANCH --bare ../upstream || die + cd ../upstream + git config user.name "UpsUser" + git config user.email "ups@ups" + cd - ) &> /dev/null output=$( diff --git a/test/setup b/test/setup index a05f7ff6..2430a6ed 100644 --- a/test/setup +++ b/test/setup @@ -1,18 +1,25 @@ #!/usr/bin/env bash -# Set this locally for Windows: -git config core.autocrlf input - set -e -# Set the GIT_SUBREPO_ROOT for testing. -source "$PWD"/.rc +export LC_ALL=C.UTF-8 # Get the location of this script SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +# Running tests depends on the whole project being git initialized. +# So, git initialize the project, if necessary. +if [ ! -d "${SCRIPT_DIR}/../.git" ]; then + git init -b master . + git config user.email "you@you" + git config user.name "YouUser" + git add . + git commit -a -m"Initial commit" + git config --list +fi + BASHLIB=$( - find "$PWD"/ -type d -name bin -o -type d -name lib | tr '\n' ':' + find "$PWD"/ -type d -name bin -o -type d -name lib | grep -v "\/\.pc\/" | tr '\n' ':' ) export BASHLIB @@ -46,17 +53,17 @@ clone-foo-and-bar() { git clone "$UPSTREAM/foo" "$OWNER/foo" ( cd "$OWNER/foo" - git config core.autocrlf input git config user.name "FooUser" git config user.email "foo@foo" + git config init.defaultBranch $DEFAULTBRANCH ) # bar will act as the subrepo git clone "$UPSTREAM/bar" "$OWNER/bar" ( cd "$OWNER/bar" - git config core.autocrlf input git config user.name "BarUser" git config user.email "bar@bar" + git config init.defaultBranch $DEFAULTBRANCH ) ) &> /dev/null || die } From 44c8058562da64240dd2f4dcc13e889b52aff24f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samo=20Poga=C4=8Dnik?= Date: Fri, 25 Oct 2024 13:53:00 +0200 Subject: [PATCH 3/6] Generate test git-repos instead of committed binaries Instead of having test repos: foo, bar and init committed in a binary form, generate them using the test/gen* scripts before starting the first 'test' session. Running 'make clean' removes the generated test repos. --- Makefile | 2 +- test/genbar | 31 +++++++++++++++++++++++++++ test/genfoo | 26 +++++++++++++++++++++++ test/geninit | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++ test/setup | 12 +++++++++++ 5 files changed, 130 insertions(+), 1 deletion(-) create mode 100755 test/genbar create mode 100755 test/genfoo create mode 100755 test/geninit diff --git a/Makefile b/Makefile index 8dd567f4..cee2f456 100644 --- a/Makefile +++ b/Makefile @@ -110,7 +110,7 @@ compgen: force $(SHARE)/zsh-completion/_git-subrepo clean: - rm -fr tmp test/tmp + rm -fr tmp test/tmp test/repo define docker-make-test docker run --rm \ diff --git a/test/genbar b/test/genbar new file mode 100755 index 00000000..9d3a2764 --- /dev/null +++ b/test/genbar @@ -0,0 +1,31 @@ +#!/bin/bash +set -xe + +if [ -z "${1}" ]; then + echo "${BASH_SOURCE[0]}: Single argument required (common test repos path)" + exit 1 +fi + +REPO="bar" +NAME="Bar" +TARGET="${1}/$REPO" +TMPREPO="${1}/tmp/$REPO" + +rm -rf "$TMPREPO" +mkdir -p "$TMPREPO" +cd "$TMPREPO" +git init --initial-branch=master . +git config user.name "${NAME}User" +git config user.email "${REPO}@${REPO}" +touch $NAME +git add $NAME +git commit -m"$NAME" +git tag A -m"$NAME" +mkdir -p bard +touch bard/Bard +git add bard +git commit -m"bard/Bard" +git config --bool core.bare true +cd - +mkdir -p "$1" +mv "$TMPREPO/.git" "$TARGET" diff --git a/test/genfoo b/test/genfoo new file mode 100755 index 00000000..a9b91671 --- /dev/null +++ b/test/genfoo @@ -0,0 +1,26 @@ +#!/bin/bash +set -xe + +if [ -z "${1}" ]; then + echo "${BASH_SOURCE[0]}: Single argument required (common test repos path)" + exit 1 +fi + +REPO="foo" +NAME="Foo" +TARGET="${1}/$REPO" +TMPREPO="${1}/tmp/$REPO" + +rm -rf "$TMPREPO" +mkdir -p "$TMPREPO" +cd "$TMPREPO" +git init --initial-branch=master . +git config user.name "${NAME}User" +git config user.email "${REPO}@${REPO}" +touch $NAME +git add $NAME +git commit -m"$NAME" +git config --bool core.bare true +cd - +mkdir -p "$1" +mv "${TMPREPO}/.git" "$TARGET" diff --git a/test/geninit b/test/geninit new file mode 100755 index 00000000..b70f9f15 --- /dev/null +++ b/test/geninit @@ -0,0 +1,60 @@ +#!/bin/bash +set -xe + +if [ -z "${1}" ]; then + echo "${BASH_SOURCE[0]}: Single argument required (common test repos path)" + exit 1 +fi + +REPO="init" +NAME="Init" +TARGET="${1}/$REPO" +TMPREPO="${1}/tmp/$REPO" + +rm -rf "$TMPREPO" +mkdir -p "$TMPREPO" +cd "$TMPREPO" +git init --initial-branch=master . +git config user.name "${NAME}User" +git config user.email "${REPO}@${REPO}" +cat < ReadMe +This is a repo to test \`git subrepo init\`. + +We will make a short history with a subdir, then we can turn that subdir into a +subrepo. +EOF +git add ReadMe +git commit -m"Initial commit" +mkdir -p doc +cat < doc/init.swim +== Subrepo Init! + +This is a file to test the \`git subrepo init\` command. +EOF +git add doc +git commit -m"Add a file in a subdir." +cat <> ReadMe + +This repo will go in the git-subrepo test suite. +EOF +git add ReadMe +git commit -m"Add a commit to the mainline." +cat <> doc/init.swim + +It lives under the doc directory which will become a subrepo. +EOF +git add doc/init.swim +git commit -m"Add a commit to the subdir." +cat <> ReadMe + +EOF +git add ReadMe +cat <> doc/init.swim + +EOF +git add doc/init.swim +git commit -m"Add a commit that affects both." +git config --bool core.bare true +cd - +mkdir -p "$1" +mv "${TMPREPO}/.git" "$TARGET" diff --git a/test/setup b/test/setup index 2430a6ed..02556c70 100644 --- a/test/setup +++ b/test/setup @@ -18,6 +18,18 @@ if [ ! -d "${SCRIPT_DIR}/../.git" ]; then git config --list fi +# Generate additional testing git repos, if not already present. +mkdir -p "${SCRIPT_DIR}/repo" +if [ ! -d "${SCRIPT_DIR}/repo/bar" ]; then + "${SCRIPT_DIR}/genbar" "${SCRIPT_DIR}/repo" +fi +if [ ! -d "${SCRIPT_DIR}/repo/foo" ]; then + "${SCRIPT_DIR}/genfoo" "${SCRIPT_DIR}/repo" +fi +if [ ! -d "${SCRIPT_DIR}/repo/init" ]; then + "${SCRIPT_DIR}/geninit" "${SCRIPT_DIR}/repo" +fi + BASHLIB=$( find "$PWD"/ -type d -name bin -o -type d -name lib | grep -v "\/\.pc\/" | tr '\n' ':' ) From 346e230c86b036be9cb6164c340a5606c01c50da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samo=20Poga=C4=8Dnik?= Date: Fri, 25 Oct 2024 13:54:31 +0200 Subject: [PATCH 4/6] Define project-wide GIT setup for all tests Disabling system/global git configs and setting default project-wide GIT configuration for the duration of running tests. Temporary GIT configuration is set inside git-subrepo project-top-dir. Also, initialize own git repo, if project isn't a git clone and ensure that the project is not in a GIT detached HEAD state. --- Makefile | 2 +- test/00-git-config.t | 55 ++++++++++++++++++++++++++++++++++++++++++++ test/setup | 8 ++++++- 3 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 test/00-git-config.t diff --git a/Makefile b/Makefile index cee2f456..f46a7d56 100644 --- a/Makefile +++ b/Makefile @@ -110,7 +110,7 @@ compgen: force $(SHARE)/zsh-completion/_git-subrepo clean: - rm -fr tmp test/tmp test/repo + rm -fr tmp test/tmp test/repo .gitconfig define docker-make-test docker run --rm \ diff --git a/test/00-git-config.t b/test/00-git-config.t new file mode 100644 index 00000000..b121c261 --- /dev/null +++ b/test/00-git-config.t @@ -0,0 +1,55 @@ +#!/usr/bin/env bash + +set -e + +source test/setup + +use Test::More + +note "Define project-wide GIT setup for all tests" + +# Get git-subrepo project top directory +PROJ_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd ) + +if [ -z "${PROJ_DIR}" ] || [ "${HOME}" != "${PROJ_DIR}" ]; then + is "${HOME}" "${PROJ_DIR}" \ + "To define project-wide GIT setup for all tests: HOME '${HOME}' should equal PROJ_DIR '${PROJ_DIR}'" +else + + # Real GIT configuration for tests is set here: + rm -f "${PROJ_DIR}/.gitconfig" + git config --global user.email "you@example.com" + git config --global user.name "Your Name" + git config --global init.defaultBranch "master" + git config --global --add safe.directory "${PROJ_DIR}" + git config --global --add safe.directory "${PROJ_DIR}/.git" + git config --list + + test-exists "${PROJ_DIR}/.gitconfig" + + # Running tests depends on the whole project being git initialized. + # So, git initialize the project, if necessary. + if [ ! -d "${PROJ_DIR}/.git" ]; then + cd "${PROJ_DIR}" + git init . + git add . + git commit -a -m"Initial commit" + cd - + fi + + test-exists "${PROJ_DIR}/.git/" + + # Running tests depends on the whole project not being in a GIT detached HEAD state. + if ! git symbolic-ref --short --quiet HEAD &> /dev/null; then + git checkout -b test + fi + + ok "$( + git symbolic-ref --short --quiet HEAD &> /dev/null + )" "Whole project is not in a GIT detached HEAD state" + +fi + +done_testing + +teardown diff --git a/test/setup b/test/setup index 02556c70..fe36ffc8 100644 --- a/test/setup +++ b/test/setup @@ -15,9 +15,15 @@ if [ ! -d "${SCRIPT_DIR}/../.git" ]; then git config user.name "YouUser" git add . git commit -a -m"Initial commit" - git config --list fi +# Disable any GIT configuration set outside this 'git-subrepo' project. +# Real GIT configuration for tests is set through the first test +# (00-git-config.t). +export XDG_CONFIG_HOME=$PWD +export HOME=$PWD +export GIT_CONFIG_NOSYSTEM=1 + # Generate additional testing git repos, if not already present. mkdir -p "${SCRIPT_DIR}/repo" if [ ! -d "${SCRIPT_DIR}/repo/bar" ]; then From 9d2d9593895955fc3d1edea5d3f2fd35ff8e0084 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samo=20Poga=C4=8Dnik?= Date: Sun, 17 Nov 2024 09:19:19 +0100 Subject: [PATCH 5/6] Fixing shellcheck errors found during docker-test --- test/clone.t | 2 +- test/config.t | 2 +- test/init.t | 4 ++-- test/issue29.t | 10 +++++----- test/issue95.t | 6 +++--- test/issue96.t | 6 +++--- test/push-after-init.t | 4 ++-- test/setup | 6 +++--- 8 files changed, 20 insertions(+), 20 deletions(-) diff --git a/test/clone.t b/test/clone.t index 4a066d7e..de37302a 100644 --- a/test/clone.t +++ b/test/clone.t @@ -10,7 +10,7 @@ clone-foo-and-bar ( mkdir -p "$OWNER/empty" - git init --initial-branch=$DEFAULTBRANCH "$OWNER/empty" + git init --initial-branch="${DEFAULTBRANCH}" "$OWNER/empty" ) # Test that the repos look ok: diff --git a/test/config.t b/test/config.t index e06e9890..83fc3cb6 100644 --- a/test/config.t +++ b/test/config.t @@ -15,7 +15,7 @@ gitrepo=$OWNER/init/doc/.gitrepo cd "$OWNER/init" git config user.email "ini@ini" git config user.name "IniUser" - git config init.defaultBranch $DEFAULTBRANCH + git config init.defaultBranch "${DEFAULTBRANCH}" git subrepo init doc ) > /dev/null diff --git a/test/init.t b/test/init.t index b3450a8e..68ecb1c5 100644 --- a/test/init.t +++ b/test/init.t @@ -24,7 +24,7 @@ output=$( cd "$OWNER/init" git config user.email "ini@ini" git config user.name "IniUser" - git config init.defaultBranch $DEFAULTBRANCH + git config init.defaultBranch "${DEFAULTBRANCH}" git subrepo init doc ) @@ -53,7 +53,7 @@ git clone "$UPSTREAM/init" "$OWNER/init" &>/dev/null cd "$OWNER/init" git config user.email "ini@ini" git config user.name "IniUser" - git config init.defaultBranch $DEFAULTBRANCH + git config init.defaultBranch "${DEFAULTBRANCH}" git subrepo init doc -r git@github.com:user/repo -b foo -M rebase ) >/dev/null diff --git a/test/issue29.t b/test/issue29.t index c12684e5..7c51a053 100644 --- a/test/issue29.t +++ b/test/issue29.t @@ -18,9 +18,9 @@ cd "$TMP" # Make 3 new repos: ( mkdir share main1 main2 - git init --initial-branch=$DEFAULTBRANCH share - git init --initial-branch=$DEFAULTBRANCH main1 - git init --initial-branch=$DEFAULTBRANCH main2 + git init --initial-branch="${DEFAULTBRANCH}" share + git init --initial-branch="${DEFAULTBRANCH}" main1 + git init --initial-branch="${DEFAULTBRANCH}" main2 ) > /dev/null # Add an empty 'readme' to the share repo: @@ -44,7 +44,7 @@ cd "$TMP" touch main1 git add main1 git commit -m "Initial main1" - git subrepo clone ../share share -b "$DEFAULTBRANCH" + git subrepo clone ../share share -b "${DEFAULTBRANCH}" ) > /dev/null # `subrepo clone` the share repo into main2: @@ -55,7 +55,7 @@ cd "$TMP" touch main2 git add main2 git commit -m "Initial main2" - git subrepo clone ../share share -b "$DEFAULTBRANCH" + git subrepo clone ../share share -b "${DEFAULTBRANCH}" ) > /dev/null diff --git a/test/issue95.t b/test/issue95.t index 46c432dc..3f2578c0 100644 --- a/test/issue95.t +++ b/test/issue95.t @@ -12,8 +12,8 @@ use Test::More # Make two new repos ( mkdir host sub - git init --initial-branch=$DEFAULTBRANCH host - git init --initial-branch=$DEFAULTBRANCH sub + git init --initial-branch="${DEFAULTBRANCH}" host + git init --initial-branch="${DEFAULTBRANCH}" sub ) > /dev/null # Initialize host repo @@ -49,7 +49,7 @@ use Test::More touch feature git add feature git commit -m "feature added" - git checkout "$DEFAULTBRANCH" + git checkout "${DEFAULTBRANCH}" ) &> /dev/null # Commit directly to subrepo diff --git a/test/issue96.t b/test/issue96.t index d1250e21..2334629b 100644 --- a/test/issue96.t +++ b/test/issue96.t @@ -11,8 +11,8 @@ use Test::More # Make two new repos ( mkdir host sub - git init --initial-branch=$DEFAULTBRANCH host - git init --initial-branch=$DEFAULTBRANCH sub + git init --initial-branch="${DEFAULTBRANCH}" host + git init --initial-branch="${DEFAULTBRANCH}" sub ) > /dev/null # Initialize host repo @@ -90,7 +90,7 @@ use Test::More # expected: successful push without conflicts is "$( cd host - git subrepo push sub -b "$DEFAULTBRANCH" -u + git subrepo push sub -b "${DEFAULTBRANCH}" -u )" \ "Subrepo 'sub' pushed to '../sub' ($DEFAULTBRANCH)." diff --git a/test/push-after-init.t b/test/push-after-init.t index e7bda8d4..93d8fc0f 100644 --- a/test/push-after-init.t +++ b/test/push-after-init.t @@ -12,14 +12,14 @@ use Test::More ( mkdir -p "$OWNER/init" cd "$OWNER/init" - git init --initial-branch=$DEFAULTBRANCH + git init --initial-branch="${DEFAULTBRANCH}" git config user.name "IniUser" git config user.email "ini@ini" mkdir doc add-new-files doc/FooBar git subrepo init doc || die mkdir ../upstream - git init --initial-branch=$DEFAULTBRANCH --bare ../upstream || die + git init --initial-branch="${DEFAULTBRANCH}" --bare ../upstream || die cd ../upstream git config user.name "UpsUser" git config user.email "ups@ups" diff --git a/test/setup b/test/setup index fe36ffc8..acb42519 100644 --- a/test/setup +++ b/test/setup @@ -59,7 +59,7 @@ mkdir -p "$UPSTREAM" "$OWNER" "$COLLAB" cp -r test/repo/{foo,bar,init} "$UPSTREAM/" DEFAULTBRANCH=$( git config --global --get init.defaultbranch || true ) -[[ -z $DEFAULTBRANCH ]] && DEFAULTBRANCH="master" +[[ -z "${DEFAULTBRANCH}" ]] && DEFAULTBRANCH="master" export DEFAULTBRANCH ### @@ -73,7 +73,7 @@ clone-foo-and-bar() { cd "$OWNER/foo" git config user.name "FooUser" git config user.email "foo@foo" - git config init.defaultBranch $DEFAULTBRANCH + git config init.defaultBranch "${DEFAULTBRANCH}" ) # bar will act as the subrepo git clone "$UPSTREAM/bar" "$OWNER/bar" @@ -81,7 +81,7 @@ clone-foo-and-bar() { cd "$OWNER/bar" git config user.name "BarUser" git config user.email "bar@bar" - git config init.defaultBranch $DEFAULTBRANCH + git config init.defaultBranch "${DEFAULTBRANCH}" ) ) &> /dev/null || die } From 2313865f4fe9d364b18448957f1727fd7637f700 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samo=20Poga=C4=8Dnik?= Date: Sun, 24 Nov 2024 11:03:31 +0000 Subject: [PATCH 6/6] Fixing github tests on macos. Using 'readlink -f' instead of 'realpath'. Added pure shell function to get relative path between two dirs. Set LC_ALL only for Linux. Echo 'uname' on 'make test' --- Makefile | 3 ++- lib/git-subrepo | 2 +- share/pnrelpath.sh | 25 +++++++++++++++++++++++++ test/setup | 4 +++- 4 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 share/pnrelpath.sh diff --git a/Makefile b/Makefile index f46a7d56..c2bf2274 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ INSTALL_BIN ?= $(PREFIX)/bin INSTALL_LIB ?= $(PREFIX)/share/$(NAME) INSTALL_EXT ?= $(INSTALL_LIB)/$(NAME).d INSTALL_MAN1 ?= $(PREFIX)/share/man/man1 -LINK_REL_DIR := $(shell realpath --relative-to=$(INSTALL_BIN) $(INSTALL_LIB)) +LINK_REL_DIR := $(shell bash share/pnrelpath.sh $(INSTALL_BIN) $(INSTALL_LIB)) # Docker variables: DOCKER_TAG ?= 0.0.6 @@ -49,6 +49,7 @@ help: .PHONY: test test: + @echo uname: '$(shell uname)' prove $(prove) $(test) test-all: test docker-tests diff --git a/lib/git-subrepo b/lib/git-subrepo index 00487e4f..65f619f1 100755 --- a/lib/git-subrepo +++ b/lib/git-subrepo @@ -12,7 +12,7 @@ set -e export FILTER_BRANCH_SQUELCH_WARNING=1 # Import Bash+ helper functions: -SUBREPO_EXT_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]}")")/git-subrepo.d" # replaced by `make install` +SUBREPO_EXT_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")/git-subrepo.d" # replaced by `make install` source "${SUBREPO_EXT_DIR}/bash+.bash" bash+:import :std can version-check diff --git a/share/pnrelpath.sh b/share/pnrelpath.sh new file mode 100644 index 00000000..800e822e --- /dev/null +++ b/share/pnrelpath.sh @@ -0,0 +1,25 @@ +#!/bin/bash +# +# from: https://unix.stackexchange.com/questions/573047/how-to-get-the-relative-path-between-two-directories +# +# Expects two parameters, source-dir and target-dir, both absolute canonicalized +# non-empty pathnames, either may be /-ended, neither need exist. +# Returns result in shell variable $REPLY as a relative path from source-dir +# to target-dir without trailing /, . if void. +# +# Algorithm is from a 2005 comp.unix.shell posting which has now ascended to +# archive.org. + +pnrelpath() { + set -- "${1%/}/" "${2%/}/" '' ## '/'-end to avoid mismatch + while [ "$1" ] && [ "$2" = "${2#"$1"}" ] ## reduce $1 to shared path + do set -- "${1%/?*/}/" "$2" "../$3" ## source/.. target ../relpath + done + REPLY="${3}${2#"$1"}" ## build result + # unless root chomp trailing '/', replace '' with '.' + [ "${REPLY#/}" ] && REPLY="${REPLY%/}" || REPLY="${REPLY:-.}" +} + +pnrelpath "$1" "$2" + +echo $REPLY diff --git a/test/setup b/test/setup index acb42519..33f2e066 100644 --- a/test/setup +++ b/test/setup @@ -2,7 +2,9 @@ set -e -export LC_ALL=C.UTF-8 +if [ "$(uname)" == "Linux" ]; then + export LC_ALL=C.UTF-8 +fi # Get the location of this script SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )