sequencer: pass absolute GIT_WORK_TREE to exec commands
[gitweb.git] / sequencer.c
index 5ca9e93888b0cdf6720c33711c52e23854f4b32b..dda854779df06e28c81bfde8848c83243028f866 100644 (file)
@@ -1013,9 +1013,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
                        opts);
                if (res || command != TODO_REWORD)
                        goto leave;
-               flags |= EDIT_MSG | AMEND_MSG;
-               if (command == TODO_REWORD)
-                       flags |= VERIFY_MSG;
+               flags |= EDIT_MSG | AMEND_MSG | VERIFY_MSG;
                msg_file = NULL;
                goto fast_forward_edit;
        }
@@ -1263,18 +1261,23 @@ static int parse_insn_line(struct todo_item *item, const char *bol, char *eol)
        if (i >= TODO_COMMENT)
                return -1;
 
+       /* Eat up extra spaces/ tabs before object name */
+       padding = strspn(bol, " \t");
+       bol += padding;
+
        if (item->command == TODO_NOOP) {
+               if (bol != eol)
+                       return error(_("%s does not accept arguments: '%s'"),
+                                    command_to_string(item->command), bol);
                item->commit = NULL;
                item->arg = bol;
                item->arg_len = eol - bol;
                return 0;
        }
 
-       /* Eat up extra spaces/ tabs before object name */
-       padding = strspn(bol, " \t");
        if (!padding)
-               return -1;
-       bol += padding;
+               return error(_("missing arguments for %s"),
+                            command_to_string(item->command));
 
        if (item->command == TODO_EXEC) {
                item->commit = NULL;
@@ -1880,6 +1883,8 @@ static int do_exec(const char *command_line)
        fprintf(stderr, "Executing: %s\n", command_line);
        child_argv[0] = command_line;
        argv_array_pushf(&child_env, "GIT_DIR=%s", absolute_path(get_git_dir()));
+       argv_array_pushf(&child_env, "GIT_WORK_TREE=%s",
+                        absolute_path(get_git_work_tree()));
        status = run_command_v_opt_cd_env(child_argv, RUN_USING_SHELL, NULL,
                                          child_env.argv);
 
@@ -2583,7 +2588,10 @@ int transform_todos(unsigned flags)
                        strbuf_addf(&buf, " %s", oid);
                }
                /* add all the rest */
-               strbuf_addf(&buf, " %.*s\n", item->arg_len, item->arg);
+               if (!item->arg_len)
+                       strbuf_addch(&buf, '\n');
+               else
+                       strbuf_addf(&buf, " %.*s\n", item->arg_len, item->arg);
        }
 
        i = write_message(buf.buf, buf.len, todo_file, 0);