Merge branch 'jn/cherry-revert-message-clean-up' into next

* jn/cherry-revert-message-clean-up:
  tests: fix syntax error in "Use advise() for hints" test
  cherry-pick/revert: Use advise() for hints
  cherry-pick/revert: Use error() for failure message
  Introduce advise() to print hints
  Eliminate “Finished cherry-pick/revert” message
This commit is contained in:
Junio C Hamano
2010-08-21 23:33:11 -07:00
6 changed files with 78 additions and 49 deletions

View File

@@ -112,25 +112,19 @@ $ git tag pu-anchor pu
$ git rebase master
* Applying: Redo "revert" using three-way merge machinery.
First trying simple merge strategy to cherry-pick.
Finished one cherry-pick.
* Applying: Remove git-apply-patch-script.
First trying simple merge strategy to cherry-pick.
Simple cherry-pick fails; trying Automatic cherry-pick.
Removing Documentation/git-apply-patch-script.txt
Removing git-apply-patch-script
Finished one cherry-pick.
* Applying: Document "git cherry-pick" and "git revert"
First trying simple merge strategy to cherry-pick.
Finished one cherry-pick.
* Applying: mailinfo and applymbox updates
First trying simple merge strategy to cherry-pick.
Finished one cherry-pick.
* Applying: Show commits in topo order and name all commits.
First trying simple merge strategy to cherry-pick.
Finished one cherry-pick.
* Applying: More documentation updates.
First trying simple merge strategy to cherry-pick.
Finished one cherry-pick.
------------------------------------------------
The temporary tag 'pu-anchor' is me just being careful, in case 'git

View File

@@ -231,27 +231,30 @@ static void set_author_ident_env(const char *message)
sha1_to_hex(commit->object.sha1));
}
static char *help_msg(void)
static void advise(const char *advice, ...)
{
va_list params;
va_start(params, advice);
vreportf("hint: ", advice, params);
va_end(params);
}
static void print_advice(void)
{
struct strbuf helpbuf = STRBUF_INIT;
char *msg = getenv("GIT_CHERRY_PICK_HELP");
if (msg)
return msg;
strbuf_addstr(&helpbuf, " After resolving the conflicts,\n"
"mark the corrected paths with 'git add <paths>' or 'git rm <paths>'\n"
"and commit the result");
if (action == CHERRY_PICK) {
strbuf_addf(&helpbuf, " with: \n"
"\n"
" git commit -c %s\n",
sha1_to_hex(commit->object.sha1));
if (msg) {
fprintf(stderr, "%s\n", msg);
return;
}
else
strbuf_addch(&helpbuf, '.');
return strbuf_detach(&helpbuf, NULL);
advise("after resolving the conflicts, mark the corrected paths");
advise("with 'git add <paths>' or 'git rm <paths>'");
if (action == CHERRY_PICK)
advise("and commit the result with 'git commit -c %s'",
find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV));
}
static void write_message(struct strbuf *msgbuf, const char *filename)
@@ -392,7 +395,6 @@ static int do_pick_commit(void)
struct commit_message msg = { NULL, NULL, NULL, NULL, NULL };
char *defmsg = NULL;
struct strbuf msgbuf = STRBUF_INIT;
struct strbuf mebuf = STRBUF_INIT;
int res;
if (no_commit) {
@@ -489,9 +491,6 @@ static int do_pick_commit(void)
}
}
strbuf_addf(&mebuf, "%s of commit %s", me,
find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV));
if (!strategy || !strcmp(strategy, "recursive") || action == REVERT) {
res = do_recursive_merge(base, next, base_label, next_label,
head, &msgbuf);
@@ -500,7 +499,6 @@ static int do_pick_commit(void)
struct commit_list *common = NULL;
struct commit_list *remotes = NULL;
strbuf_addf(&mebuf, " with strategy %s", strategy);
write_message(&msgbuf, defmsg);
commit_list_insert(base, &common);
@@ -512,17 +510,17 @@ static int do_pick_commit(void)
}
if (res) {
fprintf(stderr, "Automatic %s failed.%s\n",
mebuf.buf, help_msg());
error("could not %s %s... %s",
action == REVERT ? "revert" : "apply",
find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV),
msg.subject);
print_advice();
rerere(allow_rerere_auto);
} else {
if (!no_commit)
res = run_git_commit(defmsg);
if (!res)
fprintf(stderr, "Finished %s.\n", mebuf.buf);
}
strbuf_release(&mebuf);
free_message(&msg);
free(defmsg);

View File

@@ -181,7 +181,6 @@ Conflicts:
esac
exit 1
}
echo >&2 "Finished one $me."
# If we are cherry-pick, and if the merge did not result in
# hand-editing, we will hit this commit and inherit the original

View File

@@ -114,9 +114,9 @@ AUTOSQUASH=
test "$(git config --bool rebase.autosquash)" = "true" && AUTOSQUASH=t
NEVER_FF=
GIT_CHERRY_PICK_HELP=" After resolving the conflicts,
mark the corrected paths with 'git add <paths>', and
run 'git rebase --continue'"
GIT_CHERRY_PICK_HELP="\
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' and run 'git rebase --continue'"
export GIT_CHERRY_PICK_HELP
warn () {

View File

@@ -38,6 +38,26 @@ test_expect_success 'failed cherry-pick does not advance HEAD' '
test "$head" = "$newhead"
'
test_expect_success 'advice from failed cherry-pick' "
git checkout -f initial^0 &&
git read-tree -u --reset HEAD &&
git clean -d -f -f -q -x &&
git update-index --refresh &&
git diff-index --exit-code HEAD &&
picked=\$(git rev-parse --short picked) &&
cat <<-EOF >expected &&
error: could not apply \$picked... picked
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit -c \$picked'
EOF
test_must_fail git cherry-pick picked 2>actual &&
test_cmp expected actual
"
test_expect_success 'failed cherry-pick produces dirty index' '
git checkout -f initial^0 &&

View File

@@ -35,36 +35,54 @@ test_expect_success setup '
'
test_expect_success 'cherry-pick first..fourth works' '
cat <<-EOF >expected &&
Finished cherry-pick of commit $(git rev-parse --short second).
Finished cherry-pick of commit $(git rev-parse --short third).
Finished cherry-pick of commit $(git rev-parse --short fourth).
cat <<-\EOF >expected &&
[master OBJID] second
Author: A U Thor <author@example.com>
1 files changed, 1 insertions(+), 0 deletions(-)
[master OBJID] third
Author: A U Thor <author@example.com>
1 files changed, 1 insertions(+), 0 deletions(-)
[master OBJID] fourth
Author: A U Thor <author@example.com>
1 files changed, 1 insertions(+), 0 deletions(-)
EOF
git checkout -f master &&
git reset --hard first &&
test_tick &&
git cherry-pick first..fourth 2>actual &&
git cherry-pick first..fourth >actual &&
git diff --quiet other &&
git diff --quiet HEAD other &&
test_cmp expected actual &&
sed -e "s/$_x05[0-9a-f][0-9a-f]/OBJID/" <actual >actual.fuzzy &&
test_cmp expected actual.fuzzy &&
check_head_differs_from fourth
'
test_expect_success 'cherry-pick --strategy resolve first..fourth works' '
cat <<-EOF >expected &&
Finished cherry-pick of commit $(git rev-parse --short second) with strategy resolve.
Finished cherry-pick of commit $(git rev-parse --short third) with strategy resolve.
Finished cherry-pick of commit $(git rev-parse --short fourth) with strategy resolve.
cat <<-\EOF >expected &&
Trying simple merge.
[master OBJID] second
Author: A U Thor <author@example.com>
1 files changed, 1 insertions(+), 0 deletions(-)
Trying simple merge.
[master OBJID] third
Author: A U Thor <author@example.com>
1 files changed, 1 insertions(+), 0 deletions(-)
Trying simple merge.
[master OBJID] fourth
Author: A U Thor <author@example.com>
1 files changed, 1 insertions(+), 0 deletions(-)
EOF
git checkout -f master &&
git reset --hard first &&
test_tick &&
git cherry-pick --strategy resolve first..fourth 2>actual &&
git cherry-pick --strategy resolve first..fourth >actual &&
git diff --quiet other &&
git diff --quiet HEAD other &&
test_cmp expected actual &&
sed -e "s/$_x05[0-9a-f][0-9a-f]/OBJID/" <actual >actual.fuzzy &&
test_cmp expected actual.fuzzy &&
check_head_differs_from fourth
'