Skip to content

Commit 2cd517c

Browse files
committed
Merge branch 'jk/maint-remote-mirror-safer'
* jk/maint-remote-mirror-safer: remote: allow "-t" with fetch mirrors
2 parents efd02e9 + 3eafdc9 commit 2cd517c

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)