1
0
mirror of https://github.com/git/git synced 2024-07-05 00:58:49 +00:00

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>
This commit is contained in:
Junio C Hamano 2009-12-25 10:08:04 -08:00
parent cfc5789ada
commit 9d9a2f4aba
2 changed files with 130 additions and 1 deletions

View File

@ -11,6 +11,8 @@
#include "builtin.h"
#include "tree.h"
#include "parse-options.h"
#include "resolve-undo.h"
#include "string-list.h"
static int abbrev;
static int show_deleted;
@ -18,6 +20,7 @@ static int show_cached;
static int show_others;
static int show_stage;
static int show_unmerged;
static int show_resolve_undo;
static int show_modified;
static int show_killed;
static int show_valid_bit;
@ -37,6 +40,7 @@ static const char *tag_removed = "";
static const char *tag_other = "";
static const char *tag_killed = "";
static const char *tag_modified = "";
static const char *tag_resolve_undo = "";
static void show_dir_entry(const char *tag, struct dir_entry *ent)
{
@ -155,6 +159,38 @@ static void show_ce_entry(const char *tag, struct cache_entry *ce)
write_name_quoted(ce->name + offset, stdout, line_terminator);
}
static int show_one_ru(struct string_list_item *item, void *cbdata)
{
int offset = prefix_offset;
const char *path = item->string;
struct resolve_undo_info *ui = item->util;
int i, len;
len = strlen(path);
if (len < prefix_len)
return 0; /* outside of the prefix */
if (!match_pathspec(pathspec, path, len, prefix_len, ps_matched))
return 0; /* uninterested */
for (i = 0; i < 3; i++) {
if (!ui->mode[i])
continue;
printf("%s%06o %s %d\t", tag_resolve_undo, ui->mode[i],
abbrev
? find_unique_abbrev(ui->sha1[i], abbrev)
: sha1_to_hex(ui->sha1[i]),
i + 1);
write_name_quoted(path + offset, stdout, line_terminator);
}
return 0;
}
static void show_ru_info(const char *prefix)
{
if (!the_index.resolve_undo)
return;
for_each_string_list(show_one_ru, the_index.resolve_undo, NULL);
}
static void show_files(struct dir_struct *dir, const char *prefix)
{
int i;
@ -454,6 +490,8 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
DIR_HIDE_EMPTY_DIRECTORIES),
OPT_BOOLEAN('u', "unmerged", &show_unmerged,
"show unmerged files in the output"),
OPT_BOOLEAN(0, "resolve-undo", &show_resolve_undo,
"show resolve-undo information"),
{ OPTION_CALLBACK, 'x', "exclude", &dir.exclude_list[EXC_CMDL], "pattern",
"skip files matching pattern",
0, option_parse_exclude },
@ -490,6 +528,7 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
tag_modified = "C ";
tag_other = "? ";
tag_killed = "K ";
tag_resolve_undo = "U ";
}
if (show_modified || show_others || show_deleted || (dir.flags & DIR_SHOW_IGNORED) || show_killed)
require_work_tree = 1;
@ -529,7 +568,7 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
/* With no flags, we default to showing the cached files */
if (!(show_stage | show_deleted | show_others | show_unmerged |
show_killed | show_modified))
show_killed | show_modified | show_resolve_undo))
show_cached = 1;
if (prefix)
@ -544,6 +583,8 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
overlay_tree_on_cache(with_tree, prefix);
}
show_files(&dir, prefix);
if (show_resolve_undo)
show_ru_info(prefix);
if (ps_matched) {
int bad;

88
t/t2030-unresolve-info.sh Executable file
View File

@ -0,0 +1,88 @@
#!/bin/sh
test_description='undoing resolution'
. ./test-lib.sh
check_resolve_undo () {
msg=$1
shift
while case $# in
0) break ;;
1|2|3) die "Bug in check-resolve-undo test" ;;
esac
do
path=$1
shift
for stage in 1 2 3
do
sha1=$1
shift
case "$sha1" in
'') continue ;;
esac
sha1=$(git rev-parse --verify "$sha1")
printf "100644 %s %s\t%s\n" $sha1 $stage $path
done
done >"$msg.expect" &&
git ls-files --resolve-undo >"$msg.actual" &&
test_cmp "$msg.expect" "$msg.actual"
}
prime_resolve_undo () {
git reset --hard &&
git checkout second^0 &&
test_tick &&
test_must_fail git merge third^0 &&
echo merge does not leave anything &&
check_resolve_undo empty &&
echo different >file &&
git add file &&
echo resolving records &&
check_resolve_undo recorded file initial:file second:file third:file
}
test_expect_success setup '
test_commit initial file first &&
git branch side &&
git branch another &&
test_commit second file second &&
git checkout side &&
test_commit third file third &&
git checkout another &&
test_commit fourth file fourth &&
git checkout master
'
test_expect_success 'add records switch clears' '
prime_resolve_undo &&
test_tick &&
git commit -m merged &&
echo committing keeps &&
check_resolve_undo kept file initial:file second:file third:file &&
git checkout second^0 &&
echo switching clears &&
check_resolve_undo cleared
'
test_expect_success 'rm records reset clears' '
prime_resolve_undo &&
test_tick &&
git commit -m merged &&
echo committing keeps &&
check_resolve_undo kept file initial:file second:file third:file &&
echo merge clears upfront &&
test_must_fail git merge fourth^0 &&
check_resolve_undo nuked &&
git rm -f file &&
echo resolving records &&
check_resolve_undo recorded file initial:file HEAD:file fourth:file &&
git reset --hard &&
echo resetting discards &&
check_resolve_undo discarded
'
test_done