Skip to content

Commit cdf4a75

Browse files
dschogitster
authored andcommitted
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>
1 parent fe61935 commit cdf4a75

File tree

2 files changed

+17
-20
lines changed

2 files changed

+17
-20
lines changed

builtin-reset.c

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,26 +46,14 @@ static inline int is_merge(void)
4646

4747
static int unmerged_files(void)
4848
{
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;
6957
}
7058

7159
static int reset_index_file(const unsigned char *sha1, int is_hard_reset)

t/t7102-reset.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ test_expect_success 'giving a non existing revision should fail' '
5959
check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc
6060
'
6161

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+
6271
test_expect_success \
6372
'giving paths with options different than --mixed should fail' '
6473
! git reset --soft -- first &&

0 commit comments

Comments
 (0)