]> asedeno.scripts.mit.edu Git - git.git/commitdiff
builtin-reset: do not call "ls-files --unmerged"
authorJohannes Schindelin <Johannes.Schindelin@gmx.de>
Sat, 3 Nov 2007 14:33:01 +0000 (14:33 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 6 Nov 2007 06:47:22 +0000 (22:47 -0800)
Since reset is a builtin now, it can use the full power of libgit.a
and check for unmerged entries itself.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin-reset.c
t/t7102-reset.sh

index 5467e36c73766494ba23d03fd23a9cbf03d05b95..79792eebf2466edebef73546908cfe63ab08de65 100644 (file)
@@ -46,26 +46,14 @@ static inline int is_merge(void)
 
 static int unmerged_files(void)
 {
-       char b;
-       ssize_t len;
-       struct child_process cmd;
-       const char *argv_ls_files[] = {"ls-files", "--unmerged", NULL};
-
-       memset(&cmd, 0, sizeof(cmd));
-       cmd.argv = argv_ls_files;
-       cmd.git_cmd = 1;
-       cmd.out = -1;
-
-       if (start_command(&cmd))
-               die("Could not run sub-command: git ls-files");
-
-       len = xread(cmd.out, &b, 1);
-       if (len < 0)
-               die("Could not read output from git ls-files: %s",
-                                               strerror(errno));
-       finish_command(&cmd);
-
-       return len;
+       int i;
+       read_cache();
+       for (i = 0; i < active_nr; i++) {
+               struct cache_entry *ce = active_cache[i];
+               if (ce_stage(ce))
+                       return 1;
+       }
+       return 0;
 }
 
 static int reset_index_file(const unsigned char *sha1, int is_hard_reset)
index cea9afb764226d3086450cb7c53c881bb9803eec..506767d2d7085724187d451a5972eaedd513ce81 100755 (executable)
@@ -59,6 +59,15 @@ test_expect_success 'giving a non existing revision should fail' '
        check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc
 '
 
+test_expect_success 'reset --soft with unmerged index should fail' '
+       touch .git/MERGE_HEAD &&
+       echo "100644 44c5b5884550c17758737edcced463447b91d42b 1 un" |
+               git update-index --index-info &&
+       ! git reset --soft HEAD &&
+       rm .git/MERGE_HEAD &&
+       git rm --cached -- un
+'
+
 test_expect_success \
        'giving paths with options different than --mixed should fail' '
        ! git reset --soft -- first &&