mirror of
https://github.com/git/git
synced 2024-08-25 02:35:46 +00:00
am: add --show-current-patch
Pointing the user to $GIT_DIR/rebase-apply may encourage them to mess around in there, which is not a good thing. With this, the user does not have to keep the path around somewhere (because after a couple of commands, the path may be out of scrollback buffer) when they need to look at the patch. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
5be1f00a9a
commit
984913a210
|
@ -16,7 +16,7 @@ SYNOPSIS
|
|||
[--exclude=<path>] [--include=<path>] [--reject] [-q | --quiet]
|
||||
[--[no-]scissors] [-S[<keyid>]] [--patch-format=<format>]
|
||||
[(<mbox> | <Maildir>)...]
|
||||
'git am' (--continue | --skip | --abort)
|
||||
'git am' (--continue | --skip | --abort | --show-current-patch)
|
||||
|
||||
DESCRIPTION
|
||||
-----------
|
||||
|
@ -167,6 +167,10 @@ default. You can use `--no-utf8` to override this.
|
|||
--abort::
|
||||
Restore the original branch and abort the patching operation.
|
||||
|
||||
--show-current-patch::
|
||||
Show the patch being applied when "git am" is stopped because
|
||||
of conflicts.
|
||||
|
||||
DISCUSSION
|
||||
----------
|
||||
|
||||
|
|
32
builtin/am.c
32
builtin/am.c
|
@ -1831,8 +1831,7 @@ static void am_run(struct am_state *state, int resume)
|
|||
git_config_get_bool("advice.amworkdir", &advice_amworkdir);
|
||||
|
||||
if (advice_amworkdir)
|
||||
printf_ln(_("The copy of the patch that failed is found in: %s"),
|
||||
am_path(state, "patch"));
|
||||
printf_ln(_("Use 'git am --show-current-patch' to see the failed patch"));
|
||||
|
||||
die_user_resolve(state);
|
||||
}
|
||||
|
@ -2121,6 +2120,23 @@ static void am_abort(struct am_state *state)
|
|||
am_destroy(state);
|
||||
}
|
||||
|
||||
static int show_patch(struct am_state *state)
|
||||
{
|
||||
struct strbuf sb = STRBUF_INIT;
|
||||
const char *patch_path;
|
||||
int len;
|
||||
|
||||
patch_path = am_path(state, msgnum(state));
|
||||
len = strbuf_read_file(&sb, patch_path, 0);
|
||||
if (len < 0)
|
||||
die_errno(_("failed to read '%s'"), patch_path);
|
||||
|
||||
setup_pager();
|
||||
write_in_full(1, sb.buf, sb.len);
|
||||
strbuf_release(&sb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* parse_options() callback that validates and sets opt->value to the
|
||||
* PATCH_FORMAT_* enum value corresponding to `arg`.
|
||||
|
@ -2149,7 +2165,8 @@ enum resume_mode {
|
|||
RESUME_APPLY,
|
||||
RESUME_RESOLVED,
|
||||
RESUME_SKIP,
|
||||
RESUME_ABORT
|
||||
RESUME_ABORT,
|
||||
RESUME_SHOW_PATCH
|
||||
};
|
||||
|
||||
static int git_am_config(const char *k, const char *v, void *cb)
|
||||
|
@ -2171,6 +2188,7 @@ int cmd_am(int argc, const char **argv, const char *prefix)
|
|||
int patch_format = PATCH_FORMAT_UNKNOWN;
|
||||
enum resume_mode resume = RESUME_FALSE;
|
||||
int in_progress;
|
||||
int ret = 0;
|
||||
|
||||
const char * const usage[] = {
|
||||
N_("git am [<options>] [(<mbox> | <Maildir>)...]"),
|
||||
|
@ -2249,6 +2267,9 @@ int cmd_am(int argc, const char **argv, const char *prefix)
|
|||
OPT_CMDMODE(0, "abort", &resume,
|
||||
N_("restore the original branch and abort the patching operation."),
|
||||
RESUME_ABORT),
|
||||
OPT_CMDMODE(0, "show-current-patch", &resume,
|
||||
N_("show the patch being applied."),
|
||||
RESUME_SHOW_PATCH),
|
||||
OPT_BOOL(0, "committer-date-is-author-date",
|
||||
&state.committer_date_is_author_date,
|
||||
N_("lie about committer date")),
|
||||
|
@ -2359,11 +2380,14 @@ int cmd_am(int argc, const char **argv, const char *prefix)
|
|||
case RESUME_ABORT:
|
||||
am_abort(&state);
|
||||
break;
|
||||
case RESUME_SHOW_PATCH:
|
||||
ret = show_patch(&state);
|
||||
break;
|
||||
default:
|
||||
die("BUG: invalid resume value");
|
||||
}
|
||||
|
||||
am_state_release(&state);
|
||||
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -1077,7 +1077,7 @@ _git_am ()
|
|||
{
|
||||
__git_find_repo_path
|
||||
if [ -d "$__git_repo_path"/rebase-apply ]; then
|
||||
__gitcomp "--skip --continue --resolved --abort"
|
||||
__gitcomp "--skip --continue --resolved --abort --show-current-patch"
|
||||
return
|
||||
fi
|
||||
case "$cur" in
|
||||
|
|
|
@ -662,6 +662,11 @@ test_expect_success 'am pauses on conflict' '
|
|||
test -d .git/rebase-apply
|
||||
'
|
||||
|
||||
test_expect_success 'am --show-current-patch' '
|
||||
git am --show-current-patch >actual.patch &&
|
||||
test_cmp .git/rebase-apply/0001 actual.patch
|
||||
'
|
||||
|
||||
test_expect_success 'am --skip works' '
|
||||
echo goodbye >expected &&
|
||||
git am --skip &&
|
||||
|
|
Loading…
Reference in a new issue