summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2019-06-17 17:15:15 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-06-17 17:15:15 (GMT)
commit9b3897ab0620261585831e356168b56759849481 (patch)
tree3fae73cf58ce54acec26cc52edf5dcfe653f345d /builtin
parent86d87307c1c490282749e278380b9a258de0b46c (diff)
parent7663e438c5ca5a1dbcfcb1a9cbf68480362998a2 (diff)
downloadgit-9b3897ab0620261585831e356168b56759849481.zip
git-9b3897ab0620261585831e356168b56759849481.tar.gz
git-9b3897ab0620261585831e356168b56759849481.tar.bz2
Merge branch 'jk/am-i-resolved-fix'
"git am -i --resolved" segfaulted after trying to see a commit as if it were a tree, which has been corrected. * jk/am-i-resolved-fix: am: fix --interactive HEAD tree resolution am: drop tty requirement for --interactive am: read interactive input from stdin am: simplify prompt response handling
Diffstat (limited to 'builtin')
-rw-r--r--builtin/am.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/builtin/am.c b/builtin/am.c
index 912d982..78389d0 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -1339,9 +1339,10 @@ static void write_index_patch(const struct am_state *state)
struct rev_info rev_info;
FILE *fp;
- if (!get_oid_tree("HEAD", &head))
- tree = lookup_tree(the_repository, &head);
- else
+ if (!get_oid("HEAD", &head)) {
+ struct commit *commit = lookup_commit_or_die(&head, "HEAD");
+ tree = get_commit_tree(commit);
+ } else
tree = lookup_tree(the_repository,
the_repository->hash_algo->empty_tree);
@@ -1643,11 +1644,8 @@ static int do_interactive(struct am_state *state)
{
assert(state->msg);
- if (!isatty(0))
- die(_("cannot be interactive without stdin connected to a terminal."));
-
for (;;) {
- const char *reply;
+ char reply[64];
puts(_("Commit Body is:"));
puts("--------------------------");
@@ -1659,11 +1657,11 @@ static int do_interactive(struct am_state *state)
* in your translation. The program will only accept English
* input at this point.
*/
- reply = git_prompt(_("Apply? [y]es/[n]o/[e]dit/[v]iew patch/[a]ccept all: "), PROMPT_ECHO);
+ printf(_("Apply? [y]es/[n]o/[e]dit/[v]iew patch/[a]ccept all: "));
+ if (!fgets(reply, sizeof(reply), stdin))
+ die("unable to read from stdin; aborting");
- if (!reply) {
- continue;
- } else if (*reply == 'y' || *reply == 'Y') {
+ if (*reply == 'y' || *reply == 'Y') {
return 0;
} else if (*reply == 'a' || *reply == 'A') {
state->interactive = 0;
@@ -2334,6 +2332,9 @@ int cmd_am(int argc, const char **argv, const char *prefix)
argv_array_push(&paths, mkpath("%s/%s", prefix, argv[i]));
}
+ if (state.interactive && !paths.argc)
+ die(_("interactive mode requires patches on the command line"));
+
am_setup(&state, patch_format, paths.argv, keep_cr);
argv_array_clear(&paths);