Skip to content

Commit 2dd96ea

Browse files
committed
Merge branch 'jc/fetch-param' into maint
* jc/fetch-param: fetch --all/--multiple: keep all the fetched branch information builtin-fetch --all/--multi: propagate options correctly t5521: fix and modernize
2 parents 162b464 + e6cc510 commit 2dd96ea

2 files changed

Lines changed: 88 additions & 33 deletions

File tree

builtin-fetch.c

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,17 @@ static void check_not_current_branch(struct ref *ref_map)
651651
"of non-bare repository", current_branch->refname);
652652
}
653653

654+
static int truncate_fetch_head(void)
655+
{
656+
char *filename = git_path("FETCH_HEAD");
657+
FILE *fp = fopen(filename, "w");
658+
659+
if (!fp)
660+
return error("cannot open %s: %s\n", filename, strerror(errno));
661+
fclose(fp);
662+
return 0;
663+
}
664+
654665
static int do_fetch(struct transport *transport,
655666
struct refspec *refs, int ref_count)
656667
{
@@ -672,11 +683,9 @@ static int do_fetch(struct transport *transport,
672683

673684
/* if not appending, truncate FETCH_HEAD */
674685
if (!append && !dry_run) {
675-
char *filename = git_path("FETCH_HEAD");
676-
FILE *fp = fopen(filename, "w");
677-
if (!fp)
678-
return error("cannot open %s: %s\n", filename, strerror(errno));
679-
fclose(fp);
686+
int errcode = truncate_fetch_head();
687+
if (errcode)
688+
return errcode;
680689
}
681690

682691
ref_map = get_ref_map(transport, refs, ref_count, tags, &autotags);
@@ -784,23 +793,36 @@ static int add_remote_or_group(const char *name, struct string_list *list)
784793
static int fetch_multiple(struct string_list *list)
785794
{
786795
int i, result = 0;
787-
const char *argv[] = { "fetch", NULL, NULL, NULL, NULL, NULL, NULL };
788-
int argc = 1;
796+
const char *argv[11] = { "fetch", "--append" };
797+
int argc = 2;
789798

790799
if (dry_run)
791800
argv[argc++] = "--dry-run";
792801
if (prune)
793802
argv[argc++] = "--prune";
803+
if (update_head_ok)
804+
argv[argc++] = "--update-head-ok";
805+
if (force)
806+
argv[argc++] = "--force";
807+
if (keep)
808+
argv[argc++] = "--keep";
794809
if (verbosity >= 2)
795810
argv[argc++] = "-v";
796811
if (verbosity >= 1)
797812
argv[argc++] = "-v";
798813
else if (verbosity < 0)
799814
argv[argc++] = "-q";
800815

816+
if (!append && !dry_run) {
817+
int errcode = truncate_fetch_head();
818+
if (errcode)
819+
return errcode;
820+
}
821+
801822
for (i = 0; i < list->nr; i++) {
802823
const char *name = list->items[i].string;
803824
argv[argc] = name;
825+
argv[argc + 1] = NULL;
804826
if (verbosity >= 0)
805827
printf("Fetching %s\n", name);
806828
if (run_command_v_opt(argv, RUN_GIT_CMD)) {

t/t5521-pull-options.sh

Lines changed: 59 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,57 +4,90 @@ test_description='pull options'
44

55
. ./test-lib.sh
66

7-
D=`pwd`
8-
97
test_expect_success 'setup' '
108
mkdir parent &&
119
(cd parent && git init &&
1210
echo one >file && git add file &&
1311
git commit -m one)
1412
'
1513

16-
cd "$D"
17-
1814
test_expect_success 'git pull -q' '
1915
mkdir clonedq &&
20-
cd clonedq &&
21-
git pull -q "$D/parent" >out 2>err &&
22-
test ! -s out
16+
(cd clonedq && git init &&
17+
git pull -q "../parent" >out 2>err &&
18+
test ! -s err &&
19+
test ! -s out)
2320
'
2421

25-
cd "$D"
26-
2722
test_expect_success 'git pull' '
2823
mkdir cloned &&
29-
cd cloned &&
30-
git pull "$D/parent" >out 2>err &&
31-
test -s out
24+
(cd cloned && git init &&
25+
git pull "../parent" >out 2>err &&
26+
test -s err &&
27+
test ! -s out)
3228
'
33-
cd "$D"
3429

3530
test_expect_success 'git pull -v' '
3631
mkdir clonedv &&
37-
cd clonedv &&
38-
git pull -v "$D/parent" >out 2>err &&
39-
test -s out
32+
(cd clonedv && git init &&
33+
git pull -v "../parent" >out 2>err &&
34+
test -s err &&
35+
test ! -s out)
4036
'
4137

42-
cd "$D"
43-
4438
test_expect_success 'git pull -v -q' '
4539
mkdir clonedvq &&
46-
cd clonedvq &&
47-
git pull -v -q "$D/parent" >out 2>err &&
48-
test ! -s out
40+
(cd clonedvq && git init &&
41+
git pull -v -q "../parent" >out 2>err &&
42+
test ! -s out &&
43+
test ! -s err)
4944
'
5045

51-
cd "$D"
52-
5346
test_expect_success 'git pull -q -v' '
5447
mkdir clonedqv &&
55-
cd clonedqv &&
56-
git pull -q -v "$D/parent" >out 2>err &&
57-
test -s out
48+
(cd clonedqv && git init &&
49+
git pull -q -v "../parent" >out 2>err &&
50+
test ! -s out &&
51+
test -s err)
52+
'
53+
54+
test_expect_success 'git pull --force' '
55+
mkdir clonedoldstyle &&
56+
(cd clonedoldstyle && git init &&
57+
cat >>.git/config <<-\EOF &&
58+
[remote "one"]
59+
url = ../parent
60+
fetch = refs/heads/master:refs/heads/mirror
61+
[remote "two"]
62+
url = ../parent
63+
fetch = refs/heads/master:refs/heads/origin
64+
[branch "master"]
65+
remote = two
66+
merge = refs/heads/master
67+
EOF
68+
git pull two &&
69+
test_commit A &&
70+
git branch -f origin &&
71+
git pull --all --force
72+
)
73+
'
74+
75+
test_expect_success 'git pull --all' '
76+
mkdir clonedmulti &&
77+
(cd clonedmulti && git init &&
78+
cat >>.git/config <<-\EOF &&
79+
[remote "one"]
80+
url = ../parent
81+
fetch = refs/heads/*:refs/remotes/one/*
82+
[remote "two"]
83+
url = ../parent
84+
fetch = refs/heads/*:refs/remotes/two/*
85+
[branch "master"]
86+
remote = one
87+
merge = refs/heads/master
88+
EOF
89+
git pull --all
90+
)
5891
'
5992

6093
test_done

0 commit comments

Comments
 (0)