Skip to content

Commit 3eafdc9

Browse files
peffgitster
authored andcommitted
remote: allow "-t" with fetch mirrors
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0990248 commit 3eafdc9

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

builtin/remote.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ static int add(int argc, const char **argv)
193193

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

199199
name = argv[0];
200200
url = argv[1];

t/t5505-remote.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,21 @@ test_expect_success 'fetch mirrors do not act as mirrors during push' '
347347
)
348348
'
349349

350+
test_expect_success 'add fetch mirror with specific branches' '
351+
git init --bare mirror-fetch/track &&
352+
(cd mirror-fetch/track &&
353+
git remote add --mirror=fetch -t heads/new parent ../parent
354+
)
355+
'
356+
357+
test_expect_success 'fetch mirror respects specific branches' '
358+
(cd mirror-fetch/track &&
359+
git fetch parent &&
360+
git rev-parse --verify refs/heads/new &&
361+
test_must_fail git rev-parse --verify refs/heads/renamed
362+
)
363+
'
364+
350365
test_expect_success 'add --mirror=push' '
351366
mkdir mirror-push &&
352367
git init --bare mirror-push/public &&
@@ -382,6 +397,13 @@ test_expect_success 'push mirrors do not act as mirrors during fetch' '
382397
)
383398
'
384399

400+
test_expect_success 'push mirrors do not allow you to specify refs' '
401+
git init mirror-push/track &&
402+
(cd mirror-push/track &&
403+
test_must_fail git remote add --mirror=push -t new public ../public
404+
)
405+
'
406+
385407
test_expect_success 'add alt && prune' '
386408
(mkdir alttst &&
387409
cd alttst &&

0 commit comments

Comments
 (0)