Skip to content

Commit

Permalink
remote: allow "-t" with fetch mirrors
Browse files Browse the repository at this point in the history
Commit 13fc2c1 (remote: disallow some nonsensical option
combinations, 2011-03-30) made it impossible to use "remote
add -t foo --mirror". The argument was that specifying
specific branches is useless because:

  1. Push mirrors do not want a refspec at all.

  2. The point of fetch mirroring is to use a broad refspec
     like "refs/*", but using "-t" overrides that.

Point (1) is valid; "-t" with push mirrors is useless. But
point (2) ignored another side effect of using --mirror: it
fetches the refs directly into the refs/ namespace as they
are found upstream, instead of placing them in a
separate-remote layout.

So 13fc2c1 was overly constrictive, and disallowed
reasonable specific-branch mirroring, like:

  git remote add -t heads/foo -t heads/bar --mirror=fetch

which makes the local "foo" and "bar" branches direct
mirrors of the remote, but does not fetch anything else.

This patch restores the original behavior, but only for
fetch mirrors.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jeff King authored and Junio C Hamano committed May 26, 2011
1 parent 0990248 commit 3eafdc9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions builtin/remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ static int add(int argc, const char **argv)

if (mirror && master)
die("specifying a master branch makes no sense with --mirror");
if (mirror && track.nr)
die("specifying branches to track makes no sense with --mirror");
if (mirror && !(mirror & MIRROR_FETCH) && track.nr)
die("specifying branches to track makes sense only with fetch mirrors");

name = argv[0];
url = argv[1];
Expand Down
22 changes: 22 additions & 0 deletions t/t5505-remote.sh
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,21 @@ test_expect_success 'fetch mirrors do not act as mirrors during push' '
)
'

test_expect_success 'add fetch mirror with specific branches' '
git init --bare mirror-fetch/track &&
(cd mirror-fetch/track &&
git remote add --mirror=fetch -t heads/new parent ../parent
)
'

test_expect_success 'fetch mirror respects specific branches' '
(cd mirror-fetch/track &&
git fetch parent &&
git rev-parse --verify refs/heads/new &&
test_must_fail git rev-parse --verify refs/heads/renamed
)
'

test_expect_success 'add --mirror=push' '
mkdir mirror-push &&
git init --bare mirror-push/public &&
Expand Down Expand Up @@ -382,6 +397,13 @@ test_expect_success 'push mirrors do not act as mirrors during fetch' '
)
'

test_expect_success 'push mirrors do not allow you to specify refs' '
git init mirror-push/track &&
(cd mirror-push/track &&
test_must_fail git remote add --mirror=push -t new public ../public
)
'

test_expect_success 'add alt && prune' '
(mkdir alttst &&
cd alttst &&
Expand Down

0 comments on commit 3eafdc9

Please sign in to comment.