Skip to content

Commit b03bf53

Browse files
jrosdahladmorgan
authored andcommitted
Make reclone with implicit branch update branch in .gitrepo correctly
If the subrepo is tracking a branch and you reclone using git subrepo clone --force $URL without specifying -b/--branch then the branch setting in .gitrepo is not updated.
1 parent c9ec2a6 commit b03bf53

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/git-subrepo

+7
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,13 @@ subrepo:clone() {
488488
fi
489489
o "Remove the old subdir."
490490
RUN git rm -r -- "$subdir"
491+
492+
if [[ -z $override_branch ]]; then
493+
o "Determine the upstream head branch."
494+
get-upstream-head-branch
495+
subrepo_branch="$output"
496+
override_branch="$output" # Force update of the branch in .gitrepo
497+
fi
491498
else
492499
assert-subdir-empty
493500
if [[ -z $subrepo_branch ]]; then

test/reclone.t

+8-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ clone-foo-and-bar
1616
test-exists \
1717
"$OWNER/foo/bar/bard/"
1818

19+
# Test that reclone is not done if not needed.
1920
export XYZ=1
2021
is "$(
2122
cd "$OWNER/foo"
@@ -24,19 +25,25 @@ is "$(
2425
"Subrepo 'bar' is up to date." \
2526
"No reclone if same commit"
2627

28+
# Test that reclone of a different ref works.
2729
(
2830
cd "$OWNER/foo"
2931
git subrepo --quiet clone --force "$UPSTREAM/bar" --branch=refs/tags/A
3032
)
3133

34+
is "$(git -C "$OWNER"/foo subrepo config bar branch)" \
35+
"Subrepo 'bar' option 'branch' has value 'refs/tags/A'."
3236
test-exists \
3337
"!$OWNER/foo/bar/bard/"
3438

39+
# Test that reclone back to (implicit) master works.
3540
(
3641
cd "$OWNER/foo"
37-
git subrepo --quiet clone -f "$UPSTREAM/bar" --branch=master
42+
git subrepo --quiet clone -f "$UPSTREAM/bar"
3843
)
3944

45+
is "$(git -C "$OWNER"/foo subrepo config bar branch)" \
46+
"Subrepo 'bar' option 'branch' has value 'master'."
4047
test-exists \
4148
"$OWNER/foo/bar/bard/"
4249

0 commit comments

Comments
 (0)