Skip to content

Commit 1303c97

Browse files
author
Joel Rosdahl
committed
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 5d6aba9 commit 1303c97

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/git-subrepo

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,13 @@ subrepo:clone() {
478478
fi
479479
o "Remove the old subdir."
480480
RUN git rm -r -- "$subdir"
481+
482+
if [[ -z $override_branch ]]; then
483+
o "Determine the upstream head branch."
484+
get-upstream-head-branch
485+
subrepo_branch="$output"
486+
override_branch="$output" # Force update of the branch in .gitrepo
487+
fi
481488
else
482489
assert-subdir-empty
483490
if [[ -z $subrepo_branch ]]; then

test/reclone.t

Lines changed: 8 additions & 1 deletion
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)