From ceff6e9c8cdad3631157d2c32e2eaf048d1162ae Mon Sep 17 00:00:00 2001 From: Michele Martone Date: Thu, 2 Dec 2021 16:35:46 +0100 Subject: [PATCH 1/3] Add test for current style push of nested subrepo Assuming both bar/ and bar/baz/ have been created with 'git-subrepo clone', a 'git-subrepo push bar' takes contents of bar/baz/* as well, as if bar/baz/ were not another subrepo. This test confirms this current style. --- test/push-nested.t | 74 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 test/push-nested.t diff --git a/test/push-nested.t b/test/push-nested.t new file mode 100644 index 00000000..895f52c0 --- /dev/null +++ b/test/push-nested.t @@ -0,0 +1,74 @@ +#!/usr/bin/env bash + +set -e + +source test/setup + +nested_fix=0 + +use Test::More + +clone-foo-and-bar + +# Add subrepo twice; of which one nested in a subrepo subdir (it's bar but could be any other) +( + # In the main repo: + cd "$OWNER/foo" + + # Clone a subrepo into a subdir + git subrepo clone "$UPSTREAM/bar" + + # Clone another subrepo into a nested subdir (here it's bar -- no e.g. baz in current fixture) + git subrepo clone "$UPSTREAM/bar" "bar/bar" + + # Make a commit in a subrepo: + add-new-files bar/FooBar + + # Make a commit in a subrepo nested in a subrepo: + add-new-files bar/bar/FooBaz +) &> /dev/null || die + +# Do the subrepo push to another branch: +{ + message=$( + cd "$OWNER/foo" + git subrepo push bar/bar --branch newbar + git subrepo pull bar --branch newbar # FooBaz + ) + + message=$( + cd "$OWNER/foo" + git subrepo push bar --branch newbar # FooBar only or bar/FooBaz, too ? + ) + + # Test the output: + is "$message" \ + "Subrepo 'bar' pushed to '$UPSTREAM/bar' (newbar)." \ + 'First push message is correct ' +} + +# Pull the changes from UPSTREAM/bar in OWNER/bar +( + cd "$OWNER/bar" + git fetch + git checkout newbar +) &> /dev/null || die + +test-exists \ + "$OWNER/bar/FooBar" + +test-exists \ + "$OWNER/bar/FooBaz" + +if [[ $nested_fix == 1 ]] ; then + # nested subrepo skipped at push: no bar/bar + [[ ! -f "$OWNER/bar/bar/FooBaz" ]] +else + # nested subrepo (in subdir bar/bar) added as well + test-exists \ + "$OWNER/bar/bar/FooBaz" +fi + +done_testing + +teardown From 90058dd9ffec39465fdfa03d3fea1df30ab6efd7 Mon Sep 17 00:00:00 2001 From: Michele Martone Date: Thu, 2 Dec 2021 16:37:02 +0100 Subject: [PATCH 2/3] One may consider adding nested subrepos a bug With such expectation, git-subrepo would fail the test. --- test/push-nested.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/push-nested.t b/test/push-nested.t index 895f52c0..082f4509 100644 --- a/test/push-nested.t +++ b/test/push-nested.t @@ -4,7 +4,7 @@ set -e source test/setup -nested_fix=0 +nested_fix=1 use Test::More From 507279be45793815158e879b06e3dee9a55c7d7e Mon Sep 17 00:00:00 2001 From: Michele Martone Date: Thu, 2 Dec 2021 17:06:41 +0100 Subject: [PATCH 3/3] Fix #553 Assuming "bar" and "baz" in "bar/baz" are both subrepos, make "git-subrepo push bar" to skip "baz" -- for that, one would use "git-subrepo push bar/baz" instead. See also test/push-nested.t. --- lib/git-subrepo | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/git-subrepo b/lib/git-subrepo index 05498c7b..2f0453fb 100755 --- a/lib/git-subrepo +++ b/lib/git-subrepo @@ -812,6 +812,20 @@ subrepo:branch() { "$subref" "$branch" fi + # Mechanism to skip subdirs containing subrepos during a push. + # TODO: 1) mention dependency on 'find'; 2) may be turned on/off on option. + if which find > /dev/null; then + o "Checking $subdir for nested subdirs to avoid" + local subdirs + mapfile -t subdirs < <(cd -- "$subdir"; find -mindepth 1 -type d -exec 'test' '-f' '{}/.gitrepo' ';' -print) + if [[ ${#subdirs[@]} -gt 0 ]]; then + for d in "${subdirs[@]}"; do + o "Found $d: will rebase to exclude it"; + git filter-branch -f --index-filter "git rm -r --cached --ignore-unmatch \"${d}\"" "$branch" || true + done + fi + fi + o "Remove the .gitrepo file from $first_gitrepo_commit..$branch" local filter=$branch [[ $first_gitrepo_commit ]] && filter=$first_gitrepo_commit..$branch