From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Subject: [PATCH 3/9] resolve-undo: basic tests
Date: Tue, 29 Dec 2009 13:42:32 -0800 [thread overview]
Message-ID: <1262122958-9378-4-git-send-email-gitster@pobox.com> (raw)
In-Reply-To: <1262122958-9378-1-git-send-email-gitster@pobox.com>
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>
---
builtin-ls-files.c | 43 +++++++++++++++++++++-
t/t2030-unresolve-info.sh | 88 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 130 insertions(+), 1 deletions(-)
create mode 100755 t/t2030-unresolve-info.sh
diff --git a/builtin-ls-files.c b/builtin-ls-files.c
index c9a03e5..ef3a068 100644
--- a/builtin-ls-files.c
+++ b/builtin-ls-files.c
@@ -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;
diff --git a/t/t2030-unresolve-info.sh b/t/t2030-unresolve-info.sh
new file mode 100755
index 0000000..785c8b3
--- /dev/null
+++ b/t/t2030-unresolve-info.sh
@@ -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
--
1.6.6
next prev parent reply other threads:[~2009-12-29 21:43 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-21 18:58 [PATCH/RFC 0/3] git rerere unresolve file Johannes Sixt
2009-11-21 19:00 ` [PATCH/RFC 1/3] rerere: keep a list of resolved files in MERGE_RR Johannes Sixt
2009-11-21 19:01 ` [PATCH/RFC 2/3] rerere: make recording of the preimage reusable Johannes Sixt
2009-11-21 19:02 ` [PATCH/RFC 3/3] git rerere unresolve file Johannes Sixt
2009-11-22 2:53 ` [PATCH/RFC 0/3] " Junio C Hamano
2009-11-22 14:19 ` Johannes Sixt
2009-11-24 23:40 ` Nanako Shiraishi
2009-12-29 21:42 ` [PATCH 0/9] Undoing conflict resolution Junio C Hamano
2009-12-29 21:42 ` [PATCH 1/9] builtin-merge.c: use standard active_cache macros Junio C Hamano
2009-12-29 21:42 ` [PATCH 2/9] resolve-undo: record resolved conflicts in a new index extension section Junio C Hamano
2009-12-29 21:42 ` Junio C Hamano [this message]
2009-12-29 21:42 ` [PATCH 4/9] resolve-undo: allow plumbing to clear the information Junio C Hamano
2009-12-29 21:42 ` [PATCH 5/9] resolve-undo: "checkout -m path" uses resolve-undo information Junio C Hamano
2009-12-29 21:42 ` [PATCH 6/9] resolve-undo: teach "update-index --unresolve" to use resolve-undo info Junio C Hamano
2009-12-29 21:42 ` [PATCH 7/9] rerere: remove silly 1024-byte line limit Junio C Hamano
2009-12-29 21:42 ` [PATCH 8/9] rerere: refactor rerere logic to make it independent from I/O Junio C Hamano
2009-12-29 21:42 ` [PATCH 9/9] rerere forget path: forget recorded resolution Junio C Hamano
2010-01-05 21:25 ` Johannes Sixt
2010-01-06 1:06 ` Junio C Hamano
2010-01-06 8:55 ` Johannes Sixt
2010-01-06 16:58 ` Junio C Hamano
2010-01-06 21:59 ` Junio C Hamano
2010-01-08 21:55 ` Johannes Sixt
2010-01-08 23:20 ` Junio C Hamano
2010-01-11 1:58 ` Junio C Hamano
2010-01-11 19:22 ` Johannes Sixt
2010-01-11 20:05 ` Junio C Hamano
2010-01-11 21:05 ` Johannes Sixt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1262122958-9378-4-git-send-email-gitster@pobox.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).