Browse Source

Merge branch 'jc/fetch-param'

* jc/fetch-param:
  fetch --all/--multiple: keep all the fetched branch information
  builtin-fetch --all/--multi: propagate options correctly
  t5521: fix and modernize
maint
Junio C Hamano 15 years ago
parent
commit
512c916941
  1. 36
      builtin-fetch.c
  2. 85
      t/t5521-pull-options.sh

36
builtin-fetch.c

@ -651,6 +651,17 @@ static void check_not_current_branch(struct ref *ref_map) @@ -651,6 +651,17 @@ static void check_not_current_branch(struct ref *ref_map)
"of non-bare repository", current_branch->refname);
}

static int truncate_fetch_head(void)
{
char *filename = git_path("FETCH_HEAD");
FILE *fp = fopen(filename, "w");

if (!fp)
return error("cannot open %s: %s\n", filename, strerror(errno));
fclose(fp);
return 0;
}

static int do_fetch(struct transport *transport,
struct refspec *refs, int ref_count)
{
@ -672,11 +683,9 @@ static int do_fetch(struct transport *transport, @@ -672,11 +683,9 @@ static int do_fetch(struct transport *transport,

/* if not appending, truncate FETCH_HEAD */
if (!append && !dry_run) {
char *filename = git_path("FETCH_HEAD");
FILE *fp = fopen(filename, "w");
if (!fp)
return error("cannot open %s: %s\n", filename, strerror(errno));
fclose(fp);
int errcode = truncate_fetch_head();
if (errcode)
return errcode;
}

ref_map = get_ref_map(transport, refs, ref_count, tags, &autotags);
@ -784,13 +793,19 @@ static int add_remote_or_group(const char *name, struct string_list *list) @@ -784,13 +793,19 @@ static int add_remote_or_group(const char *name, struct string_list *list)
static int fetch_multiple(struct string_list *list)
{
int i, result = 0;
const char *argv[] = { "fetch", NULL, NULL, NULL, NULL, NULL, NULL };
int argc = 1;
const char *argv[11] = { "fetch", "--append" };
int argc = 2;

if (dry_run)
argv[argc++] = "--dry-run";
if (prune)
argv[argc++] = "--prune";
if (update_head_ok)
argv[argc++] = "--update-head-ok";
if (force)
argv[argc++] = "--force";
if (keep)
argv[argc++] = "--keep";
if (verbosity >= 2)
argv[argc++] = "-v";
if (verbosity >= 1)
@ -798,9 +813,16 @@ static int fetch_multiple(struct string_list *list) @@ -798,9 +813,16 @@ static int fetch_multiple(struct string_list *list)
else if (verbosity < 0)
argv[argc++] = "-q";

if (!append && !dry_run) {
int errcode = truncate_fetch_head();
if (errcode)
return errcode;
}

for (i = 0; i < list->nr; i++) {
const char *name = list->items[i].string;
argv[argc] = name;
argv[argc + 1] = NULL;
if (verbosity >= 0)
printf("Fetching %s\n", name);
if (run_command_v_opt(argv, RUN_GIT_CMD)) {

85
t/t5521-pull-options.sh

@ -4,8 +4,6 @@ test_description='pull options' @@ -4,8 +4,6 @@ test_description='pull options'

. ./test-lib.sh

D=`pwd`

test_expect_success 'setup' '
mkdir parent &&
(cd parent && git init &&
@ -13,48 +11,83 @@ test_expect_success 'setup' ' @@ -13,48 +11,83 @@ test_expect_success 'setup' '
git commit -m one)
'

cd "$D"

test_expect_success 'git pull -q' '
mkdir clonedq &&
cd clonedq &&
git pull -q "$D/parent" >out 2>err &&
test ! -s out
(cd clonedq && git init &&
git pull -q "../parent" >out 2>err &&
test ! -s err &&
test ! -s out)
'

cd "$D"

test_expect_success 'git pull' '
mkdir cloned &&
cd cloned &&
git pull "$D/parent" >out 2>err &&
test -s out
(cd cloned && git init &&
git pull "../parent" >out 2>err &&
test -s err &&
test ! -s out)
'
cd "$D"

test_expect_success 'git pull -v' '
mkdir clonedv &&
cd clonedv &&
git pull -v "$D/parent" >out 2>err &&
test -s out
(cd clonedv && git init &&
git pull -v "../parent" >out 2>err &&
test -s err &&
test ! -s out)
'

cd "$D"

test_expect_success 'git pull -v -q' '
mkdir clonedvq &&
cd clonedvq &&
git pull -v -q "$D/parent" >out 2>err &&
test ! -s out
(cd clonedvq && git init &&
git pull -v -q "../parent" >out 2>err &&
test ! -s out &&
test ! -s err)
'

cd "$D"

test_expect_success 'git pull -q -v' '
mkdir clonedqv &&
cd clonedqv &&
git pull -q -v "$D/parent" >out 2>err &&
test -s out
(cd clonedqv && git init &&
git pull -q -v "../parent" >out 2>err &&
test ! -s out &&
test -s err)
'

test_expect_success 'git pull --force' '
mkdir clonedoldstyle &&
(cd clonedoldstyle && git init &&
cat >>.git/config <<-\EOF &&
[remote "one"]
url = ../parent
fetch = refs/heads/master:refs/heads/mirror
[remote "two"]
url = ../parent
fetch = refs/heads/master:refs/heads/origin
[branch "master"]
remote = two
merge = refs/heads/master
EOF
git pull two &&
test_commit A &&
git branch -f origin &&
git pull --all --force
)
'

test_expect_success 'git pull --all' '
mkdir clonedmulti &&
(cd clonedmulti && git init &&
cat >>.git/config <<-\EOF &&
[remote "one"]
url = ../parent
fetch = refs/heads/*:refs/remotes/one/*
[remote "two"]
url = ../parent
fetch = refs/heads/*:refs/remotes/two/*
[branch "master"]
remote = one
merge = refs/heads/master
EOF
git pull --all
)
'

test_done

Loading…
Cancel
Save