From: Junio C Hamano Date: Wed, 22 Oct 2008 00:58:21 +0000 (-0700) Subject: Merge branch 'js/maint-fetch-update-head' X-Git-Tag: v1.6.1-rc1~114 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/ca6c06b2efe2f55c498670efcb419bce35678e03?ds=inline;hp=-c Merge branch 'js/maint-fetch-update-head' * js/maint-fetch-update-head: pull: allow "git pull origin $something:$current_branch" into an unborn branch Fix fetch/pull when run without --update-head-ok Conflicts: t/t5510-fetch.sh --- ca6c06b2efe2f55c498670efcb419bce35678e03 diff --combined builtin-fetch.c index e008ee92ab,57c161d35b..f151cfa2fd --- a/builtin-fetch.c +++ b/builtin-fetch.c @@@ -521,8 -521,8 +521,8 @@@ static void find_non_local_tags(struct will_fetch(head, ref->old_sha1))) { string_list_insert(ref_name, &new_refs); - rm = alloc_ref_from_str(ref_name); - rm->peer_ref = alloc_ref_from_str(ref_name); + rm = alloc_ref(ref_name); + rm->peer_ref = alloc_ref(ref_name); hashcpy(rm->old_sha1, ref_sha1); **tail = rm; @@@ -534,6 -534,19 +534,19 @@@ string_list_clear(&new_refs, 0); } + static void check_not_current_branch(struct ref *ref_map) + { + struct branch *current_branch = branch_get(NULL); + + if (is_bare_repository() || !current_branch) + return; + + for (; ref_map; ref_map = ref_map->next) + if (ref_map->peer_ref && !strcmp(current_branch->refname, + ref_map->peer_ref->name)) + die("Refusing to fetch into current branch"); + } + static int do_fetch(struct transport *transport, struct refspec *refs, int ref_count) { @@@ -558,6 -571,8 +571,8 @@@ } ref_map = get_ref_map(transport, refs, ref_count, tags, &autotags); + if (!update_head_ok) + check_not_current_branch(ref_map); for (rm = ref_map; rm; rm = rm->next) { if (rm->peer_ref) diff --combined t/t5510-fetch.sh index 9aae4965da,52094e78dc..9e679b402d --- a/t/t5510-fetch.sh +++ b/t/t5510-fetch.sh @@@ -303,24 -303,16 +303,36 @@@ test_expect_success 'pushing nonexisten ' +test_expect_success 'auto tag following fetches minimum' ' + + cd "$D" && + git clone .git follow && + git checkout HEAD^0 && + ( + for i in 1 2 3 4 5 6 7 + do + echo $i >>file && + git commit -m $i -a && + git tag -a -m $i excess-$i || exit 1 + done + ) && + git checkout master && + ( + cd follow && + git fetch + ) +' + + test_expect_success 'refuse to fetch into the current branch' ' + + test_must_fail git fetch . side:master + + ' + + test_expect_success 'fetch into the current branch with --update-head-ok' ' + + git fetch --update-head-ok . side:master + + ' + test_done diff --combined t/t9300-fast-import.sh index 328444a306,dba3a1b48f..91b5aced1b --- a/t/t9300-fast-import.sh +++ b/t/t9300-fast-import.sh @@@ -3,9 -3,9 +3,9 @@@ # Copyright (c) 2007 Shawn Pearce # -test_description='test git-fast-import utility' +test_description='test git fast-import utility' . ./test-lib.sh -. ../diff-lib.sh ;# test-lib chdir's into trash +. "$TEST_DIRECTORY"/diff-lib.sh ;# test-lib chdir's into trash file2_data='file2 second line of EOF' @@@ -59,7 -59,7 +59,7 @@@ M 755 :4 file INPUT_END test_expect_success \ 'A: create pack from stdin' \ - 'git-fast-import --export-marks=marks.out input <expect <output && test_cmp expect output' @@@ -649,7 -649,7 +649,7 @@@ cat >expect <actual && compare_diff_raw expect actual' @@@ -670,7 -670,7 +670,7 @@@ cat >expect <actual && compare_diff_raw expect actual' @@@ -691,7 -691,7 +691,7 @@@ cat >expect <actual && compare_diff_raw expect actual' @@@ -717,7 -717,7 +717,7 @@@ cat >expect <actual && compare_diff_raw expect actual' @@@ -751,7 -751,7 +751,7 @@@ cat >expect <actual && compare_diff_raw expect actual' @@@ -775,8 -775,8 +775,8 @@@ INPUT_EN test_expect_success \ 'N: copy dirty subdirectory' \ - 'git-fast-import input <actual && @@@ -914,7 -914,7 +914,7 @@@ progress I'm done INPUT_END test_expect_success \ 'O: progress outputs as requested by input' \ - 'git-fast-import actual && + 'git fast-import actual && grep "progress " expect && test_cmp expect actual' @@@ -979,18 -979,18 +979,18 @@@ INPUT_EN test_expect_success \ 'P: supermodule & submodule mix' \ - 'git-fast-import input <input <input <