Skip to content

Commit 1d7358c

Browse files
Per Cederqvistgitster
authored andcommitted
branch.c: Relax unnecessary requirement on upstream's remote ref name
When creating an upstream relationship, we use the configured remotes and their refspecs to determine the upstream configuration settings branch.<name>.remote and branch.<name>.merge. However, if the matching refspec does not have refs/heads/<something> on the remote side, we end up rejecting the match, and failing the upstream configuration. It could be argued that when we set up an branch's upstream, we want that upstream to also be a proper branch in the remote repo. Although this is typically the common case, there are cases (as demonstrated by the previous patch in this series) where this requirement prevents a useful upstream relationship from being formed. Furthermore: - We have fundamentally no say in how the remote repo have organized its branches. The remote repo may put branches (or branch-like constructs that are insteresting for downstreams to track) outside refs/heads/*. - The user may intentionally want to track a non-branch from a remote repo, by using a branch and configured upstream in the local repo. Relaxing the checking to only require a matching remote/refspec allows the testcase introduced in the previous patch to succeed, and has no negative effect on the rest of the test suite. This patch fixes a behavior (arguably a regression) first introduced in 41c21f2 (branch.c: Validate tracking branches with refspecs instead of refs/remotes/*) on 2013-04-21 (released in >= v1.8.3.2). Signed-off-by: Johan Herland <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 62d94a3 commit 1d7358c

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

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/t3200-branch.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ test_expect_success '--merged catches invalid object names' '
871871
test_must_fail git branch --merged 0000000000000000000000000000000000000000
872872
'
873873

874-
test_expect_failure 'tracking with unexpected .fetch refspec' '
874+
test_expect_success 'tracking with unexpected .fetch refspec' '
875875
git init a &&
876876
(
877877
cd a &&

0 commit comments

Comments
 (0)