Merge branch 'js/maint-fetch-update-head'
authorJunio C Hamano <gitster@pobox.com>
Wed, 22 Oct 2008 00:58:21 +0000 (17:58 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 22 Oct 2008 00:58:21 +0000 (17:58 -0700)
* 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

1  2 
builtin-fetch.c
t/t5510-fetch.sh
t/t9300-fast-import.sh
diff --combined builtin-fetch.c
index e008ee92ab1b2f78541a411603fa812fbb0c7139,57c161d35b2e317f1fe32f39067c86508b89152e..f151cfa2fd028dd37ad0cc3b6b35b2017417fffa
@@@ -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;
        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)
  {
        }
  
        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 9aae4965dac0f2bf4bb8684c4b8d43dcb60529e9,52094e78dcd63cd7dc1ce166450c403fc32efbac..9e679b402dc826185377c431d353decd8a8a2bed
@@@ -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 328444a3068f5083e3d64e92e88660c724acffdc,dba3a1b48f70c47b405d85f140684b181e62002a..91b5aced1bcea74a66c3365e4aceff355d577f6a
@@@ -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 &&
 +    'git fast-import --export-marks=marks.out <input &&
         git whatchanged master'
  test_expect_success \
        'A: verify pack' \
@@@ -113,7 -113,7 +113,7 @@@ test_expect_success 
  
  test_expect_success \
        'A: verify marks import' \
 -      'git-fast-import \
 +      'git fast-import \
                --import-marks=marks.out \
                --export-marks=marks.new \
                </dev/null &&
@@@ -133,7 -133,7 +133,7 @@@ M 755 :2 copy-of-file
  INPUT_END
  test_expect_success \
        'A: verify marks import does not crash' \
 -      'git-fast-import --import-marks=marks.out <input &&
 +      'git fast-import --import-marks=marks.out <input &&
         git whatchanged verify--import-marks'
  test_expect_success \
        'A: verify pack' \
@@@ -166,7 -166,7 +166,7 @@@ M 755 000000000000000000000000000000000
  
  INPUT_END
  test_expect_success 'B: fail on invalid blob sha1' '
 -    test_must_fail git-fast-import <input
 +    test_must_fail git fast-import <input
  '
  rm -f .git/objects/pack_* .git/objects/index_*
  
@@@ -181,7 -181,7 +181,7 @@@ from refs/heads/maste
  
  INPUT_END
  test_expect_success 'B: fail on invalid branch name ".badbranchname"' '
 -    test_must_fail git-fast-import <input
 +    test_must_fail git fast-import <input
  '
  rm -f .git/objects/pack_* .git/objects/index_*
  
@@@ -196,7 -196,7 +196,7 @@@ from refs/heads/maste
  
  INPUT_END
  test_expect_success 'B: fail on invalid branch name "bad[branch]name"' '
 -    test_must_fail git-fast-import <input
 +    test_must_fail git fast-import <input
  '
  rm -f .git/objects/pack_* .git/objects/index_*
  
@@@ -212,7 -212,7 +212,7 @@@ from refs/heads/maste
  INPUT_END
  test_expect_success \
      'B: accept branch name "TEMP_TAG"' \
 -    'git-fast-import <input &&
 +    'git fast-import <input &&
         test -f .git/TEMP_TAG &&
         test `git rev-parse master` = `git rev-parse TEMP_TAG^`'
  rm -f .git/TEMP_TAG
  ### series C
  ###
  
 -newf=`echo hi newf | git-hash-object -w --stdin`
 +newf=`echo hi newf | git hash-object -w --stdin`
  oldf=`git rev-parse --verify master:file2`
  test_tick
  cat >input <<INPUT_END
@@@ -239,7 -239,7 +239,7 @@@ D file
  INPUT_END
  test_expect_success \
      'C: incremental import create pack from stdin' \
 -    'git-fast-import <input &&
 +    'git fast-import <input &&
         git whatchanged branch'
  test_expect_success \
        'C: verify pack' \
@@@ -297,7 -297,7 +297,7 @@@ EO
  INPUT_END
  test_expect_success \
      'D: inline data in commit' \
 -    'git-fast-import <input &&
 +    'git fast-import <input &&
         git whatchanged branch'
  test_expect_success \
        'D: verify pack' \
@@@ -340,11 -340,11 +340,11 @@@ from refs/heads/branch^
  
  INPUT_END
  test_expect_success 'E: rfc2822 date, --date-format=raw' '
 -    test_must_fail git-fast-import --date-format=raw <input
 +    test_must_fail git fast-import --date-format=raw <input
  '
  test_expect_success \
      'E: rfc2822 date, --date-format=rfc2822' \
 -    'git-fast-import --date-format=rfc2822 <input'
 +    'git fast-import --date-format=rfc2822 <input'
  test_expect_success \
        'E: verify pack' \
        'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
@@@ -381,7 -381,7 +381,7 @@@ from refs/heads/branc
  INPUT_END
  test_expect_success \
      'F: non-fast-forward update skips' \
 -    'if git-fast-import <input
 +    'if git fast-import <input
         then
                echo BAD gfi did not fail
                return 1
@@@ -431,7 -431,7 +431,7 @@@ from refs/heads/branch~
  INPUT_END
  test_expect_success \
      'G: non-fast-forward update forced' \
 -    'git-fast-import --force <input'
 +    'git fast-import --force <input'
  test_expect_success \
        'G: verify pack' \
        'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
@@@ -467,7 -467,7 +467,7 @@@ EO
  INPUT_END
  test_expect_success \
      'H: deletall, add 1' \
 -    'git-fast-import <input &&
 +    'git fast-import <input &&
         git whatchanged H'
  test_expect_success \
        'H: verify pack' \
@@@ -507,7 -507,7 +507,7 @@@ from refs/heads/branc
  INPUT_END
  test_expect_success \
      'I: export-pack-edges' \
 -    'git-fast-import --export-pack-edges=edges.list <input'
 +    'git fast-import --export-pack-edges=edges.list <input'
  
  cat >expect <<EOF
  .git/objects/pack/pack-.pack: `git rev-parse --verify export-boundary`
@@@ -541,7 -541,7 +541,7 @@@ COMMI
  INPUT_END
  test_expect_success \
      'J: reset existing branch creates empty commit' \
 -    'git-fast-import <input'
 +    'git fast-import <input'
  test_expect_success \
        'J: branch has 1 commit, empty tree' \
        'test 1 = `git rev-list J | wc -l` &&
@@@ -571,7 -571,7 +571,7 @@@ from refs/heads/branch^
  INPUT_END
  test_expect_success \
      'K: reinit branch with from' \
 -    'git-fast-import <input'
 +    'git fast-import <input'
  test_expect_success \
      'K: verify K^1 = branch^1' \
      'test `git rev-parse --verify branch^1` \
@@@ -623,7 -623,7 +623,7 @@@ EXPECT_EN
  
  test_expect_success \
      'L: verify internal tree sorting' \
 -      'git-fast-import <input &&
 +      'git fast-import <input &&
         git diff-tree --abbrev --raw L^ L >output &&
         test_cmp expect output'
  
@@@ -649,7 -649,7 +649,7 @@@ cat >expect <<EO
  EOF
  test_expect_success \
        'M: rename file in same subdirectory' \
 -      'git-fast-import <input &&
 +      'git fast-import <input &&
         git diff-tree -M -r M1^ M1 >actual &&
         compare_diff_raw expect actual'
  
@@@ -670,7 -670,7 +670,7 @@@ cat >expect <<EO
  EOF
  test_expect_success \
        'M: rename file to new subdirectory' \
 -      'git-fast-import <input &&
 +      'git fast-import <input &&
         git diff-tree -M -r M2^ M2 >actual &&
         compare_diff_raw expect actual'
  
@@@ -691,7 -691,7 +691,7 @@@ cat >expect <<EO
  EOF
  test_expect_success \
        'M: rename subdirectory to new subdirectory' \
 -      'git-fast-import <input &&
 +      'git fast-import <input &&
         git diff-tree -M -r M3^ M3 >actual &&
         compare_diff_raw expect actual'
  
@@@ -717,7 -717,7 +717,7 @@@ cat >expect <<EO
  EOF
  test_expect_success \
        'N: copy file in same subdirectory' \
 -      'git-fast-import <input &&
 +      'git fast-import <input &&
         git diff-tree -C --find-copies-harder -r N1^ N1 >actual &&
         compare_diff_raw expect actual'
  
@@@ -751,7 -751,7 +751,7 @@@ cat >expect <<EO
  EOF
  test_expect_success \
        'N: copy then modify subdirectory' \
 -      'git-fast-import <input &&
 +      'git fast-import <input &&
         git diff-tree -C --find-copies-harder -r N2^^ N2 >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 &&
 -       test `git-rev-parse N2^{tree}` = `git-rev-parse N3^{tree}`'
 +      'git fast-import <input &&
 +       test `git rev-parse N2^{tree}` = `git rev-parse N3^{tree}`'
  
  ###
  ### series O
@@@ -815,8 -815,8 +815,8 @@@ INPUT_EN
  
  test_expect_success \
        'O: comments are all skipped' \
 -      'git-fast-import <input &&
 -       test `git-rev-parse N3` = `git-rev-parse O1`'
 +      'git fast-import <input &&
 +       test `git rev-parse N3` = `git rev-parse O1`'
  
  cat >input <<INPUT_END
  commit refs/heads/O2
@@@ -836,8 -836,8 +836,8 @@@ INPUT_EN
  
  test_expect_success \
        'O: blank lines not necessary after data commands' \
 -      'git-fast-import <input &&
 -       test `git-rev-parse N3` = `git-rev-parse O2`'
 +      'git fast-import <input &&
 +       test `git rev-parse N3` = `git rev-parse O2`'
  
  test_expect_success \
        'O: repack before next test' \
@@@ -881,7 -881,7 +881,7 @@@ commit
  INPUT_END
  test_expect_success \
        'O: blank lines not necessary after other commands' \
 -      'git-fast-import <input &&
 +      'git fast-import <input &&
         test 8 = `find .git/objects/pack -type f | wc -l` &&
         test `git rev-parse refs/tags/O3-2nd` = `git rev-parse O3^` &&
         git log --reverse --pretty=oneline O3 | sed s/^.*z// >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 <input >actual &&
 +      'git fast-import <input >actual &&
         grep "progress " <input >expect &&
         test_cmp expect actual'
  
@@@ -979,18 -979,18 +979,18 @@@ INPUT_EN
  
  test_expect_success \
        'P: supermodule & submodule mix' \
 -      'git-fast-import <input &&
 +      'git fast-import <input &&
         git checkout subuse1 &&
         rm -rf sub && mkdir sub && cd sub &&
         git init &&
-        git fetch .. refs/heads/sub:refs/heads/master &&
+        git fetch --update-head-ok .. refs/heads/sub:refs/heads/master &&
         git checkout master &&
         cd .. &&
         git submodule init &&
         git submodule update'
  
 -SUBLAST=$(git-rev-parse --verify sub)
 -SUBPREV=$(git-rev-parse --verify sub^)
 +SUBLAST=$(git rev-parse --verify sub)
 +SUBPREV=$(git rev-parse --verify sub^)
  
  cat >input <<INPUT_END
  blob
@@@ -1024,8 -1024,8 +1024,8 @@@ test_expect_success 
        'P: verbatim SHA gitlinks' \
        'git branch -D sub &&
         git gc && git prune &&
 -       git-fast-import <input &&
 -       test $(git-rev-parse --verify subuse2) = $(git-rev-parse --verify subuse1)'
 +       git fast-import <input &&
 +       test $(git rev-parse --verify subuse2) = $(git rev-parse --verify subuse1)'
  
  test_tick
  cat >input <<INPUT_END
@@@ -1045,7 -1045,7 +1045,7 @@@ DAT
  INPUT_END
  
  test_expect_success 'P: fail on inline gitlink' '
 -    test_must_fail git-fast-import <input'
 +    test_must_fail git fast-import <input'
  
  test_tick
  cat >input <<INPUT_END
@@@ -1068,6 -1068,6 +1068,6 @@@ M 160000 :1 su
  INPUT_END
  
  test_expect_success 'P: fail on blob mark in gitlink' '
 -    test_must_fail git-fast-import <input'
 +    test_must_fail git fast-import <input'
  
  test_done