Skip to content

Commit 2fa8383

Browse files
mahmoudimusmichelemartone
authored and
doak
committed
Nested (ingydotnet#1)
* 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. * One may consider adding nested subrepos a bug With such expectation, git-subrepo would fail the test. * Fix ingydotnet#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. Co-authored-by: Michele Martone <[email protected]>
1 parent 3fc0046 commit 2fa8383

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

lib/git-subrepo

+14
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,20 @@ subrepo:branch() {
840840
"$subref" "$branch"
841841
fi
842842

843+
# Mechanism to skip subdirs containing subrepos during a push.
844+
# TODO: 1) mention dependency on 'find'; 2) may be turned on/off on option.
845+
if which find > /dev/null; then
846+
o "Checking $subdir for nested subdirs to avoid"
847+
local subdirs
848+
mapfile -t subdirs < <(cd -- "$subdir"; find -mindepth 1 -type d -exec 'test' '-f' '{}/.gitrepo' ';' -print)
849+
if [[ ${#subdirs[@]} -gt 0 ]]; then
850+
for d in "${subdirs[@]}"; do
851+
o "Found $d: will rebase to exclude it";
852+
git filter-branch -f --index-filter "git rm -r --cached --ignore-unmatch \"${d}\"" "$branch" || true
853+
done
854+
fi
855+
fi
856+
843857
o "Remove the .gitrepo file from $first_gitrepo_commit..$branch"
844858
local filter=$branch
845859
[[ $first_gitrepo_commit ]] && filter=$first_gitrepo_commit..$branch

test/push-nested.t

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
source test/setup
6+
7+
nested_fix=1
8+
9+
use Test::More
10+
11+
clone-foo-and-bar
12+
13+
# Add subrepo twice; of which one nested in a subrepo subdir (it's bar but could be any other)
14+
(
15+
# In the main repo:
16+
cd "$OWNER/foo"
17+
18+
# Clone a subrepo into a subdir
19+
git subrepo clone "$UPSTREAM/bar"
20+
21+
# Clone another subrepo into a nested subdir (here it's bar -- no e.g. baz in current fixture)
22+
git subrepo clone "$UPSTREAM/bar" "bar/bar"
23+
24+
# Make a commit in a subrepo:
25+
add-new-files bar/FooBar
26+
27+
# Make a commit in a subrepo nested in a subrepo:
28+
add-new-files bar/bar/FooBaz
29+
) &> /dev/null || die
30+
31+
# Do the subrepo push to another branch:
32+
{
33+
message=$(
34+
cd "$OWNER/foo"
35+
git subrepo push bar/bar --branch newbar
36+
git subrepo pull bar --branch newbar # FooBaz
37+
)
38+
39+
message=$(
40+
cd "$OWNER/foo"
41+
git subrepo push bar --branch newbar # FooBar only or bar/FooBaz, too ?
42+
)
43+
44+
# Test the output:
45+
is "$message" \
46+
"Subrepo 'bar' pushed to '$UPSTREAM/bar' (newbar)." \
47+
'First push message is correct '
48+
}
49+
50+
# Pull the changes from UPSTREAM/bar in OWNER/bar
51+
(
52+
cd "$OWNER/bar"
53+
git fetch
54+
git checkout newbar
55+
) &> /dev/null || die
56+
57+
test-exists \
58+
"$OWNER/bar/FooBar"
59+
60+
test-exists \
61+
"$OWNER/bar/FooBaz"
62+
63+
if [[ $nested_fix == 1 ]] ; then
64+
# nested subrepo skipped at push: no bar/bar
65+
[[ ! -f "$OWNER/bar/bar/FooBaz" ]]
66+
else
67+
# nested subrepo (in subdir bar/bar) added as well
68+
test-exists \
69+
"$OWNER/bar/bar/FooBaz"
70+
fi
71+
72+
done_testing
73+
74+
teardown

0 commit comments

Comments
 (0)