resolve-undo: basic tests
Make sure that resolving a failed merge with git add records the conflicted state, committing the result keeps that state, and checking out another commit clears the state. "git ls-files" learns a new option --resolve-undo to show the recorded information. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Dec 25, 2009 at 10:08 UTC
9d9a2f4aba3650093bad952cd89e276cde4ed074
2 files changed
+130
-1
builtin-ls-files.c
+42
-1
@@ -11,6 +11,8 @@
11
#include "builtin.h"
12
#include "tree.h"
13
#include "parse-options.h"
14
+#include "resolve-undo.h"
15
+#include "string-list.h"
16
17
static int abbrev;
18
static int show_deleted;
@@ -18,6 +20,7 @@ static int show_cached;
20
static int show_others;
21
static int show_stage;
22
static int show_unmerged;
23
+static int show_resolve_undo;
24
static int show_modified;
25
static int show_killed;
26
static int show_valid_bit;
@@ -37,6 +40,7 @@ static const char *tag_removed = "";
40
static const char *tag_other = "";
41
static const char *tag_killed = "";
42
static const char *tag_modified = "";
43
+static const char *tag_resolve_undo = "";
44
45
static void show_dir_entry(const char *tag, struct dir_entry *ent)
46
{
@@ -155,6 +159,38 @@ static void show_ce_entry(const char *tag, struct cache_entry *ce)
159
write_name_quoted(ce->name + offset, stdout, line_terminator);
160
}
161
162
+static int show_one_ru(struct string_list_item *item, void *cbdata)
163
+{
164
+ int offset = prefix_offset;
165
+ const char *path = item->string;
166
+ struct resolve_undo_info *ui = item->util;
167
+ int i, len;
168
+
169
+ len = strlen(path);
170
+ if (len < prefix_len)
171
+ return 0; /* outside of the prefix */
172
+ if (!match_pathspec(pathspec, path, len, prefix_len, ps_matched))
173
+ return 0; /* uninterested */
174
+ for (i = 0; i < 3; i++) {
175
+ if (!ui->mode[i])
176
+ continue;
177
+ printf("%s%06o %s %d\t", tag_resolve_undo, ui->mode[i],
178
+ abbrev
179
+ ? find_unique_abbrev(ui->sha1[i], abbrev)
180
+ : sha1_to_hex(ui->sha1[i]),
181
+ i + 1);
182
+ write_name_quoted(path + offset, stdout, line_terminator);
183
+ }
184
+ return 0;
185
+}
186
+
187
+static void show_ru_info(const char *prefix)
188
+{
189
+ if (!the_index.resolve_undo)
190
+ return;
191
+ for_each_string_list(show_one_ru, the_index.resolve_undo, NULL);
192
+}
193
+
194
static void show_files(struct dir_struct *dir, const char *prefix)
195
{
196
int i;
@@ -454,6 +490,8 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
490
DIR_HIDE_EMPTY_DIRECTORIES),
491
OPT_BOOLEAN('u', "unmerged", &show_unmerged,
492
"show unmerged files in the output"),
493
+ OPT_BOOLEAN(0, "resolve-undo", &show_resolve_undo,
494
+ "show resolve-undo information"),
495
{ OPTION_CALLBACK, 'x', "exclude", &dir.exclude_list[EXC_CMDL], "pattern",
496
"skip files matching pattern",
497
0, option_parse_exclude },
@@ -490,6 +528,7 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
528
tag_modified = "C ";
529
tag_other = "? ";
530
tag_killed = "K ";
531
+ tag_resolve_undo = "U ";
532
}
533
if (show_modified || show_others || show_deleted || (dir.flags & DIR_SHOW_IGNORED) || show_killed)
534
require_work_tree = 1;
@@ -529,7 +568,7 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
568
569
/* With no flags, we default to showing the cached files */
570
if (!(show_stage | show_deleted | show_others | show_unmerged |
532
- show_killed | show_modified))
571
+ show_killed | show_modified | show_resolve_undo))
572
show_cached = 1;
573
574
if (prefix)
@@ -544,6 +583,8 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
583
overlay_tree_on_cache(with_tree, prefix);
584
}
585
show_files(&dir, prefix);
586
+ if (show_resolve_undo)
587
+ show_ru_info(prefix);
588
589
if (ps_matched) {
590
int bad;
t/t2030-unresolve-info.sh
new
+88
@@ -0,0 +1,88 @@
1
+#!/bin/sh
2
+
3
+test_description='undoing resolution'
4
+
5
+. ./test-lib.sh
6
+
7
+check_resolve_undo () {
8
+ msg=$1
9
+ shift
10
+ while case $# in
11
+ 0) break ;;
12
+ 1|2|3) die "Bug in check-resolve-undo test" ;;
13
+ esac
14
+ do
15
+ path=$1
16
+ shift
17
+ for stage in 1 2 3
18
+ do
19
+ sha1=$1
20
+ shift
21
+ case "$sha1" in
22
+ '') continue ;;
23
+ esac
24
+ sha1=$(git rev-parse --verify "$sha1")
25
+ printf "100644 %s %s\t%s\n" $sha1 $stage $path
26
+ done
27
+ done >"$msg.expect" &&
28
+ git ls-files --resolve-undo >"$msg.actual" &&
29
+ test_cmp "$msg.expect" "$msg.actual"
30
+}
31
+
32
+prime_resolve_undo () {
33
+ git reset --hard &&
34
+ git checkout second^0 &&
35
+ test_tick &&
36
+ test_must_fail git merge third^0 &&
37
+ echo merge does not leave anything &&
38
+ check_resolve_undo empty &&
39
+ echo different >file &&
40
+ git add file &&
41
+ echo resolving records &&
42
+ check_resolve_undo recorded file initial:file second:file third:file
43
+}
44
+
45
+test_expect_success setup '
46
+ test_commit initial file first &&
47
+ git branch side &&
48
+ git branch another &&
49
+ test_commit second file second &&
50
+ git checkout side &&
51
+ test_commit third file third &&
52
+ git checkout another &&
53
+ test_commit fourth file fourth &&
54
+ git checkout master
55
+'
56
+
57
+test_expect_success 'add records switch clears' '
58
+ prime_resolve_undo &&
59
+ test_tick &&
60
+ git commit -m merged &&
61
+ echo committing keeps &&
62
+ check_resolve_undo kept file initial:file second:file third:file &&
63
+ git checkout second^0 &&
64
+ echo switching clears &&
65
+ check_resolve_undo cleared
66
+'
67
+
68
+test_expect_success 'rm records reset clears' '
69
+ prime_resolve_undo &&
70
+ test_tick &&
71
+ git commit -m merged &&
72
+ echo committing keeps &&
73
+ check_resolve_undo kept file initial:file second:file third:file &&
74
+
75
+ echo merge clears upfront &&
76
+ test_must_fail git merge fourth^0 &&
77
+ check_resolve_undo nuked &&
78
+
79
+ git rm -f file &&
80
+ echo resolving records &&
81
+ check_resolve_undo recorded file initial:file HEAD:file fourth:file &&
82
+
83
+ git reset --hard &&
84
+ echo resetting discards &&
85
+ check_resolve_undo discarded
86
+'
87
+
88
+test_done