Merge branch 'jc/maint-co-track' into maint
authorJunio C Hamano <gitster@pobox.com>
Sun, 2 Nov 2008 21:36:14 +0000 (13:36 -0800)
committerJunio C Hamano <gitster@pobox.com>
Sun, 2 Nov 2008 21:36:14 +0000 (13:36 -0800)
* jc/maint-co-track:
Enhance hold_lock_file_for_{update,append}() API
demonstrate breakage of detached checkout with symbolic link HEAD
Fix "checkout --track -b newbranch" on detached HEAD

1  2 
builtin-revert.c
sha1_file.c
t/t7201-co.sh
diff --combined builtin-revert.c
index c41788685bf0b5bea3a3ae26615795e07a995793,e839387629461be24c0bf1dacaa3cdb48cb2a5f4..786a956f26486856c97e15ce8ab464dfb25dcbc5
@@@ -269,7 -269,7 +269,7 @@@ static int revert_or_cherry_pick(int ar
        int i;
        char *oneline, *reencoded_message = NULL;
        const char *message, *encoding;
 -      const char *defmsg = xstrdup(git_path("MERGE_MSG"));
 +      char *defmsg = xstrdup(git_path("MERGE_MSG"));
  
        git_config(git_default_config, NULL);
        me = action == REVERT ? "revert" : "cherry-pick";
         * reverse of it if we are revert.
         */
  
-       msg_fd = hold_lock_file_for_update(&msg_file, defmsg, 1);
+       msg_fd = hold_lock_file_for_update(&msg_file, defmsg,
+                                          LOCK_DIE_ON_ERROR);
  
        encoding = get_encoding(message);
        if (!encoding)
                return execv_git_cmd(args);
        }
        free(reencoded_message);
 +      free(defmsg);
  
        return 0;
  }
diff --combined sha1_file.c
index c78507152f5bccbba24a9daba55d2cd9942081ad,5cfae5d1adb8c386d4e38c1960f60fb3357c17b3..12fc767ee57103739e568a959981ca559417ecf4
@@@ -385,7 -385,7 +385,7 @@@ static void read_info_alternates(const 
  void add_to_alternates_file(const char *reference)
  {
        struct lock_file *lock = xcalloc(1, sizeof(struct lock_file));
-       int fd = hold_lock_file_for_append(lock, git_path("objects/info/alternates"), 1);
+       int fd = hold_lock_file_for_append(lock, git_path("objects/info/alternates"), LOCK_DIE_ON_ERROR);
        char *alt = mkpath("%s/objects\n", reference);
        write_or_die(fd, alt, strlen(alt));
        if (commit_lock_file(lock))
@@@ -2322,7 -2322,6 +2322,7 @@@ int force_object_loose(const unsigned c
        enum object_type type;
        char hdr[32];
        int hdrlen;
 +      int ret;
  
        if (has_loose_object(sha1))
                return 0;
        if (!buf)
                return error("cannot read sha1_file for %s", sha1_to_hex(sha1));
        hdrlen = sprintf(hdr, "%s %lu", typename(type), len) + 1;
 -      return write_loose_object(sha1, hdr, hdrlen, buf, len, mtime);
 +      ret = write_loose_object(sha1, hdr, hdrlen, buf, len, mtime);
 +      free(buf);
 +
 +      return ret;
  }
  
  int has_pack_index(const unsigned char *sha1)
diff --combined t/t7201-co.sh
index 0679abd29d907944c5c246275adfcd760f001d55,f93478f97ff8d139d4c67690e1c85f098ca90a10..c9abed6a2b18404306e281c7b5d161686f1c3b20
@@@ -330,12 -330,26 +330,26 @@@ test_expect_success 
      test "$(git config branch.track2.merge)"
      git config branch.autosetupmerge false'
  
- test_expect_success \
-     'checkout w/--track from non-branch HEAD fails' '
-     git checkout -b delete-me master &&
-     rm .git/refs/heads/delete-me &&
-     test refs/heads/delete-me = "$(git symbolic-ref HEAD)" &&
-     test_must_fail git checkout --track -b track'
+ test_expect_success 'checkout w/--track from non-branch HEAD fails' '
+     git checkout master^0 &&
+     test_must_fail git symbolic-ref HEAD &&
+     test_must_fail git checkout --track -b track &&
+     test_must_fail git rev-parse --verify track &&
+     test_must_fail git symbolic-ref HEAD &&
+     test "z$(git rev-parse master^0)" = "z$(git rev-parse HEAD)"
+ '
+ test_expect_success 'detach a symbolic link HEAD' '
+     git checkout master &&
+     git config --bool core.prefersymlinkrefs yes &&
+     git checkout side &&
+     git checkout master &&
+     it=$(git symbolic-ref HEAD) &&
+     test "z$it" = zrefs/heads/master &&
+     here=$(git rev-parse --verify refs/heads/master) &&
+     git checkout side^ &&
+     test "z$(git rev-parse --verify refs/heads/master)" = "z$here"
+ '
  
  test_expect_success 'checkout an unmerged path should fail' '
        rm -f .git/index &&
        test_cmp sample file
  '
  
 +test_expect_success 'failing checkout -b should not break working tree' '
 +      git reset --hard master &&
 +      git symbolic-ref HEAD refs/heads/master &&
 +      test_must_fail git checkout -b renamer side^ &&
 +      test $(git symbolic-ref HEAD) = refs/heads/master &&
 +      git diff --exit-code &&
 +      git diff --cached --exit-code
 +
 +'
 +
  test_done