git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCHv2 4/5] t3200: Add test demonstrating minor regression in 41c21f2

From
Johan Herland <johan@herland.net>
Date
Sep 8, 2013, 20:58 UTC
Message-ID
<1378673895-23127-5-git-send-email-johan@herland.net>
In-Reply-To
<1378673895-23127-1-git-send-email-johan@herland.net>

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.<name>.remote and branch.<name>.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 <cederp@opera.com>
Signed-off-by: Johan Herland <johan@herland.net>
---
 t/t3200-branch.sh | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
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
-- 
1.8.3.GIT
Previous: Johan HerlandNext: Johan Herland
Message 14 of 15 in “branch: Fix --track on a remote-tracking non-branch”
  1. 0/5 branch: Fix --track on a remote-tracking non-branchJohan Herland, Sep 6, 2013
  2. 1/5 t2024: Fix inconsequential typosJohan Herland, Sep 6, 2013
  3. Junio C HamanoSep 6, 2013
  4. Johan HerlandSep 6, 2013
  5. 2/5 t3200: Minor fix when preparing for tracking failureJohan Herland, Sep 6, 2013
  6. 3/5 Refer to branch.<name>.remote/merge when documenting --trackJohan Herland, Sep 6, 2013
  7. 4/5 t3200: Add test demonstrating minor regression in 41c21f2Johan Herland, Sep 6, 2013
  8. 5/5 branch.c: Relax unnecessary requirement on upstream's remote ref nameJohan Herland, Sep 6, 2013
  9. Junio C HamanoSep 6, 2013
  10. 0/5 branch: Fix --track on a remote-tracking non-branchJohan Herland, Sep 8, 2013
  11. 1/5 t2024: Fix &&-chaining and a couple of typosJohan Herland, Sep 8, 2013
  12. 2/5 t3200: Minor fix when preparing for tracking failureJohan Herland, Sep 8, 2013
  13. 3/5 Refer to branch.<name>.remote/merge when documenting --trackJohan Herland, Sep 8, 2013
  14. 4/5 t3200: Add test demonstrating minor regression in 41c21f2Johan Herland, Sep 8, 2013
  15. 5/5 branch.c: Relax unnecessary requirement on upstream's remote ref nameJohan Herland, Sep 8, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.