Skip to content

push to skip nested subrepos (as mentioned in Issue #553) #554

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions lib/git-subrepo
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
74 changes: 74 additions & 0 deletions test/push-nested.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env bash

set -e

source test/setup

nested_fix=1

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