From 5a517b1c4c94b329aab97b452e5d8e04449f9252 Mon Sep 17 00:00:00 2001 From: Johan Herland Date: Sun, 8 Sep 2013 22:58:11 +0200 Subject: t2024: Fix &&-chaining and a couple of typos Improved-by: Junio C Hamano Signed-off-by: Johan Herland Signed-off-by: Junio C Hamano diff --git a/t/t2024-checkout-dwim.sh b/t/t2024-checkout-dwim.sh index dee55e4..094b92e 100755 --- a/t/t2024-checkout-dwim.sh +++ b/t/t2024-checkout-dwim.sh @@ -104,7 +104,7 @@ test_expect_success 'setup more remotes with unconventional refspecs' ' cd repo_c && test_commit c_master && git checkout -b bar && - test_commit c_bar + test_commit c_bar && git checkout -b spam && test_commit c_spam ) && @@ -113,9 +113,9 @@ test_expect_success 'setup more remotes with unconventional refspecs' ' cd repo_d && test_commit d_master && git checkout -b baz && - test_commit f_baz + test_commit d_baz && git checkout -b eggs && - test_commit c_eggs + test_commit d_eggs ) && git remote add repo_c repo_c && git config remote.repo_c.fetch \ -- cgit v0.10.2-6-g49f6 From 81f339dc3d7f4f1dcec01f8d74be922e882ffc82 Mon Sep 17 00:00:00 2001 From: Johan Herland Date: Sun, 8 Sep 2013 22:58:12 +0200 Subject: t3200: Minor fix when preparing for tracking failure We're testing that trying to --track a ref that is not covered by any remote refspec should fail. For that, we want to have refs/remotes/local/master present, but we also want the remote.local.fetch refspec to NOT match refs/remotes/local/master (so that the tracking setup will fail, as intended). However, when doing "git fetch local" to ensure the existence of refs/remotes/local/master, we must not already have changed remote.local.fetch so as to cause refs/remotes/local/master not to be fetched. Therefore, set remote.local.fetch to refs/heads/*:refs/remotes/local/* BEFORE we fetch, and then reset it to refs/heads/s:refs/remotes/local/s AFTER we have fetched (but before we test --track). Signed-off-by: Johan Herland Signed-off-by: Junio C Hamano diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh index 44ec6a4..8f6ab8e 100755 --- a/t/t3200-branch.sh +++ b/t/t3200-branch.sh @@ -319,8 +319,9 @@ test_expect_success 'test tracking setup (non-wildcard, matching)' ' test_expect_success 'tracking setup fails on non-matching refspec' ' git config remote.local.url . && - git config remote.local.fetch refs/heads/s:refs/remotes/local/s && + git config remote.local.fetch refs/heads/*:refs/remotes/local/* && (git show-ref -q refs/remotes/local/master || git fetch local) && + git config remote.local.fetch refs/heads/s:refs/remotes/local/s && test_must_fail git branch --track my5 local/master && test_must_fail git config branch.my5.remote && test_must_fail git config branch.my5.merge -- cgit v0.10.2-6-g49f6 From fef0e991aa51481f047473e79a8f4d61f56dd60f Mon Sep 17 00:00:00 2001 From: Johan Herland Date: Sun, 8 Sep 2013 22:58:13 +0200 Subject: Refer to branch..remote/merge when documenting --track Make it easier for readers to find the actual config variables that implement the "upstream" relationship. Suggested-by: Per Cederqvist Signed-off-by: Johan Herland Signed-off-by: Junio C Hamano diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt index b7cb625..311b336 100644 --- a/Documentation/git-branch.txt +++ b/Documentation/git-branch.txt @@ -48,7 +48,8 @@ working tree to it; use "git checkout " to switch to the new branch. When a local branch is started off a remote-tracking branch, Git sets up the -branch so that 'git pull' will appropriately merge from +branch (specifically the `branch..remote` and `branch..merge` +configuration entries) so that 'git pull' will appropriately merge from the remote-tracking branch. This behavior may be changed via the global `branch.autosetupmerge` configuration flag. That setting can be overridden by using the `--track` and `--no-track` options, and @@ -156,7 +157,8 @@ This option is only applicable in non-verbose mode. -t:: --track:: - When creating a new branch, set up configuration to mark the + When creating a new branch, set up `branch..remote` and + `branch..merge` configuration entries to mark the start-point branch as "upstream" from the new branch. This configuration will tell git to show the relationship between the two branches in `git status` and `git branch -v`. Furthermore, -- cgit v0.10.2-6-g49f6 From 62d94a3aa6cc0f43f150af1d5549ca5f7b25fe0b Mon Sep 17 00:00:00 2001 From: Johan Herland Date: Sun, 8 Sep 2013 22:58:14 +0200 Subject: t3200: Add test demonstrating minor regression in 41c21f2 In 41c21f2 (branch.c: Validate tracking branches with refspecs instead of refs/remotes/*), we changed the rules for what is considered a valid tracking branch (a.k.a. upstream branch). We now use the configured remotes and their refspecs to determine whether a proposed tracking branch is in fact within the domain of a remote, and we then use that information to deduce the upstream configuration (branch..remote and branch..merge). However, with that change, we also check that - in addition to a matching refspec - the result of mapping the tracking branch through that refspec (i.e. the corresponding ref name in the remote repo) happens to start with "refs/heads/". In other words, we require that a tracking branch refers to a _branch_ in the remote repo. Now, consider that you are e.g. setting up an automated building/testing infrastructure for a group of similar "source" repositories. The build/test infrastructure consists of a central scheduler, and a number of build/test "slave" machines that perform the actual build/test work. The scheduler monitors the group of similar repos for changes (e.g. with a periodic "git fetch"), and triggers builds/tests to be run on one or more slaves. Graphically the changes flow between the repos like this: Source #1 -------v ----> Slave #1 / Source #2 -----> Scheduler -----> Slave #2 \ Source #3 -------^ ----> Slave #3 ... ... The scheduler maintains a single Git repo with each of the source repos set up as distinct remotes. The slaves also need access to all the changes from all of the source repos, so they pull from the scheduler repo, but using the following custom refspec: remote.origin.fetch = "+refs/remotes/*:refs/remotes/*" This makes all of the scheduler's remote-tracking branches automatically available as identical remote-tracking branches in each of the slaves. Now, consider what happens if a slave tries to create a local branch with one of the remote-tracking branches as upstream: git branch local_branch --track refs/remotes/source-1/some_branch Git now looks at the configured remotes (in this case there is only "origin", pointing to the scheduler's repo) and sees refs/remotes/source-1/some_branch matching origin's refspec. Mapping through that refspec we find that the corresponding remote ref name is "refs/remotes/source-1/some_branch". However, since this remote ref name does not start with "refs/heads/", we discard it as a suitable upstream, and the whole command fails. This patch adds a testcase demonstrating this failure by creating two source repos ("a" and "b") that are forwarded through a scheduler ("c") to a slave repo ("d"), that then tries create a local branch with an upstream. See the next patch in this series for the exciting conclusion to this story... Reported-by: Per Cederqvist Signed-off-by: Johan Herland Signed-off-by: Junio C Hamano diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh index 8f6ab8e..4031693 100755 --- a/t/t3200-branch.sh +++ b/t/t3200-branch.sh @@ -871,4 +871,38 @@ test_expect_success '--merged catches invalid object names' ' test_must_fail git branch --merged 0000000000000000000000000000000000000000 ' +test_expect_failure 'tracking with unexpected .fetch refspec' ' + git init a && + ( + cd a && + test_commit a + ) && + git init b && + ( + cd b && + test_commit b + ) && + git init c && + ( + cd c && + test_commit c && + git remote add a ../a && + git remote add b ../b && + git fetch --all + ) && + git init d && + ( + cd d && + git remote add c ../c && + git config remote.c.fetch "+refs/remotes/*:refs/remotes/*" && + git fetch c && + git branch --track local/a/master remotes/a/master && + test "$(git config branch.local/a/master.remote)" = "c" && + test "$(git config branch.local/a/master.merge)" = "refs/remotes/a/master" && + git rev-parse --verify a >expect && + git rev-parse --verify local/a/master >actual && + test_cmp expect actual + ) +' + test_done -- cgit v0.10.2-6-g49f6 From 1d7358c5245cd7e290146ccf96407dc8a805f314 Mon Sep 17 00:00:00 2001 From: Per Cederqvist Date: Sun, 8 Sep 2013 22:58:15 +0200 Subject: 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..remote and branch..merge. However, if the matching refspec does not have refs/heads/ 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 Signed-off-by: Junio C Hamano diff --git a/branch.c b/branch.c index beaf11d..428be60 100644 --- a/branch.c +++ b/branch.c @@ -203,8 +203,7 @@ static int check_tracking_branch(struct remote *remote, void *cb_data) struct refspec query; memset(&query, 0, sizeof(struct refspec)); query.dst = tracking_branch; - return !(remote_find_tracking(remote, &query) || - prefixcmp(query.src, "refs/heads/")); + return !remote_find_tracking(remote, &query); } static int validate_remote_tracking_branch(char *ref) diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh index 4031693..f010303 100755 --- a/t/t3200-branch.sh +++ b/t/t3200-branch.sh @@ -871,7 +871,7 @@ test_expect_success '--merged catches invalid object names' ' test_must_fail git branch --merged 0000000000000000000000000000000000000000 ' -test_expect_failure 'tracking with unexpected .fetch refspec' ' +test_expect_success 'tracking with unexpected .fetch refspec' ' git init a && ( cd a && -- cgit v0.10.2-6-g49f6 From b0f49ff13033621af06af742e3615fe905833562 Mon Sep 17 00:00:00 2001 From: Eric Sunshine Date: Sat, 14 Sep 2013 03:36:24 -0400 Subject: t3200: fix failure on case-insensitive filesystems 62d94a3a (t3200: Add test demonstrating minor regression in 41c21f2; 2013-09-08) introduced a test which creates a directory named 'a', however, on case-insensitive filesystems, this action fails with a "fatal: cannot mkdir a: File exists" error due to a file named 'A' left over from earlier tests. Resolve this problem. Signed-off-by: Eric Sunshine Signed-off-by: Junio C Hamano diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh index f010303..55c9ab0 100755 --- a/t/t3200-branch.sh +++ b/t/t3200-branch.sh @@ -872,6 +872,7 @@ test_expect_success '--merged catches invalid object names' ' ' test_expect_success 'tracking with unexpected .fetch refspec' ' + rm -rf a b c d && git init a && ( cd a && -- cgit v0.10.2-6-g49f6