Merge branch 'jc/denoise-rm-to-resolve'
[gitweb.git] / builtin / am.c
index 912d9821b18acfa0a4c1e3bed8e6c9e7b43dcdf8..1aea657a7f0b56345e1b2d5f8f32df439e278e80 100644 (file)
@@ -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;
@@ -1803,7 +1801,7 @@ static void am_run(struct am_state *state, int resume)
         */
        if (!state->rebasing) {
                am_destroy(state);
-               close_all_packs(the_repository->objects);
+               close_object_store(the_repository->objects);
                run_command_v_opt(argv_gc_auto, RUN_GIT_CMD);
        }
 }
@@ -1958,7 +1956,7 @@ static int clean_index(const struct object_id *head, const struct object_id *rem
        if (merge_tree(remote_tree))
                return -1;
 
-       remove_branch_state(the_repository);
+       remove_branch_state(the_repository, 0);
 
        return 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);