Skip to content

Commit 74051fa

Browse files
committed
Merge branch 'jh/checkout-auto-tracking' into maint
"git branch --track" had a minor regression in v1.8.3.2 and later that made it impossible to base your local work on anything but a local branch of the upstream repository you are tracking from. * jh/checkout-auto-tracking: t3200: fix failure on case-insensitive filesystems branch.c: Relax unnecessary requirement on upstream's remote ref name t3200: Add test demonstrating minor regression in 41c21f2 Refer to branch.<name>.remote/merge when documenting --track t3200: Minor fix when preparing for tracking failure t2024: Fix &&-chaining and a couple of typos
2 parents 6ba0d95 + b0f49ff commit 74051fa

File tree

4 files changed

+45
-8
lines changed

4 files changed

+45
-8
lines changed

Documentation/git-branch.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ working tree to it; use "git checkout <newbranch>" to switch to the
4848
new branch.
4949

5050
When a local branch is started off a remote-tracking branch, Git sets up the
51-
branch so that 'git pull' will appropriately merge from
51+
branch (specifically the `branch.<name>.remote` and `branch.<name>.merge`
52+
configuration entries) so that 'git pull' will appropriately merge from
5253
the remote-tracking branch. This behavior may be changed via the global
5354
`branch.autosetupmerge` configuration flag. That setting can be
5455
overridden by using the `--track` and `--no-track` options, and
@@ -156,7 +157,8 @@ This option is only applicable in non-verbose mode.
156157

157158
-t::
158159
--track::
159-
When creating a new branch, set up configuration to mark the
160+
When creating a new branch, set up `branch.<name>.remote` and
161+
`branch.<name>.merge` configuration entries to mark the
160162
start-point branch as "upstream" from the new branch. This
161163
configuration will tell git to show the relationship between the
162164
two branches in `git status` and `git branch -v`. Furthermore,

branch.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,7 @@ static int check_tracking_branch(struct remote *remote, void *cb_data)
203203
struct refspec query;
204204
memset(&query, 0, sizeof(struct refspec));
205205
query.dst = tracking_branch;
206-
return !(remote_find_tracking(remote, &query) ||
207-
prefixcmp(query.src, "refs/heads/"));
206+
return !remote_find_tracking(remote, &query);
208207
}
209208

210209
static int validate_remote_tracking_branch(char *ref)

t/t2024-checkout-dwim.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ test_expect_success 'setup more remotes with unconventional refspecs' '
104104
cd repo_c &&
105105
test_commit c_master &&
106106
git checkout -b bar &&
107-
test_commit c_bar
107+
test_commit c_bar &&
108108
git checkout -b spam &&
109109
test_commit c_spam
110110
) &&
@@ -113,9 +113,9 @@ test_expect_success 'setup more remotes with unconventional refspecs' '
113113
cd repo_d &&
114114
test_commit d_master &&
115115
git checkout -b baz &&
116-
test_commit f_baz
116+
test_commit d_baz &&
117117
git checkout -b eggs &&
118-
test_commit c_eggs
118+
test_commit d_eggs
119119
) &&
120120
git remote add repo_c repo_c &&
121121
git config remote.repo_c.fetch \

t/t3200-branch.sh

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,9 @@ test_expect_success 'test tracking setup (non-wildcard, matching)' '
319319

320320
test_expect_success 'tracking setup fails on non-matching refspec' '
321321
git config remote.local.url . &&
322-
git config remote.local.fetch refs/heads/s:refs/remotes/local/s &&
322+
git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
323323
(git show-ref -q refs/remotes/local/master || git fetch local) &&
324+
git config remote.local.fetch refs/heads/s:refs/remotes/local/s &&
324325
test_must_fail git branch --track my5 local/master &&
325326
test_must_fail git config branch.my5.remote &&
326327
test_must_fail git config branch.my5.merge
@@ -870,4 +871,39 @@ test_expect_success '--merged catches invalid object names' '
870871
test_must_fail git branch --merged 0000000000000000000000000000000000000000
871872
'
872873

874+
test_expect_success 'tracking with unexpected .fetch refspec' '
875+
rm -rf a b c d &&
876+
git init a &&
877+
(
878+
cd a &&
879+
test_commit a
880+
) &&
881+
git init b &&
882+
(
883+
cd b &&
884+
test_commit b
885+
) &&
886+
git init c &&
887+
(
888+
cd c &&
889+
test_commit c &&
890+
git remote add a ../a &&
891+
git remote add b ../b &&
892+
git fetch --all
893+
) &&
894+
git init d &&
895+
(
896+
cd d &&
897+
git remote add c ../c &&
898+
git config remote.c.fetch "+refs/remotes/*:refs/remotes/*" &&
899+
git fetch c &&
900+
git branch --track local/a/master remotes/a/master &&
901+
test "$(git config branch.local/a/master.remote)" = "c" &&
902+
test "$(git config branch.local/a/master.merge)" = "refs/remotes/a/master" &&
903+
git rev-parse --verify a >expect &&
904+
git rev-parse --verify local/a/master >actual &&
905+
test_cmp expect actual
906+
)
907+
'
908+
873909
test_done

0 commit comments

Comments
 (0)