builtin-reset: do not call "ls-files --unmerged"
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>
Johannes Schindelin committed
Nov 3, 2007 at 14:33 UTC
cdf4a751fa728273030651a769f9f45212ff50c9
2 files changed
+17
-20
builtin-reset.c
+8
-20
@@ -46,26 +46,14 @@ static inline int is_merge(void)
46
47
static int unmerged_files(void)
48
{
49
- char b;
50
- ssize_t len;
51
- struct child_process cmd;
52
- const char *argv_ls_files[] = {"ls-files", "--unmerged", NULL};
53
-
54
- memset(&cmd, 0, sizeof(cmd));
55
- cmd.argv = argv_ls_files;
56
- cmd.git_cmd = 1;
57
- cmd.out = -1;
58
-
59
- if (start_command(&cmd))
60
- die("Could not run sub-command: git ls-files");
61
-
62
- len = xread(cmd.out, &b, 1);
63
- if (len < 0)
64
- die("Could not read output from git ls-files: %s",
65
- strerror(errno));
66
- finish_command(&cmd);
67
-
68
- return len;
49
+ int i;
50
+ read_cache();
51
+ for (i = 0; i < active_nr; i++) {
52
+ struct cache_entry *ce = active_cache[i];
53
+ if (ce_stage(ce))
54
+ return 1;
55
+ }
56
+ return 0;
57
}
58
59
static int reset_index_file(const unsigned char *sha1, int is_hard_reset)
t/t7102-reset.sh
+9
@@ -59,6 +59,15 @@ test_expect_success 'giving a non existing revision should fail' '
59
check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc
60
'
61
62
+test_expect_success 'reset --soft with unmerged index should fail' '
63
+ touch .git/MERGE_HEAD &&
64
+ echo "100644 44c5b5884550c17758737edcced463447b91d42b 1 un" |
65
+ git update-index --index-info &&
66
+ ! git reset --soft HEAD &&
67
+ rm .git/MERGE_HEAD &&
68
+ git rm --cached -- un
69
+'
70
+
71
test_expect_success \
72
'giving paths with options different than --mixed should fail' '
73
! git reset --soft -- first &&