Merge branch 'mh/avoid-rewriting-packed-refs' into maint
[gitweb.git] / sequencer.c
index 17360eb38afa05253fac3013af227ceac6b23d94..2882d5312078e6e732bb2167db6849609fedd6af 100644 (file)
@@ -1862,12 +1862,15 @@ static int error_failed_squash(struct commit *commit,
 
 static int do_exec(const char *command_line)
 {
+       struct argv_array child_env = ARGV_ARRAY_INIT;
        const char *child_argv[] = { NULL, NULL };
        int dirty, status;
 
        fprintf(stderr, "Executing: %s\n", command_line);
        child_argv[0] = command_line;
-       status = run_command_v_opt(child_argv, RUN_USING_SHELL);
+       argv_array_pushf(&child_env, "GIT_DIR=%s", absolute_path(get_git_dir()));
+       status = run_command_v_opt_cd_env(child_argv, RUN_USING_SHELL, NULL,
+                                         child_env.argv);
 
        /* force re-reading of the cache */
        if (discard_cache() < 0 || read_cache() < 0)
@@ -1897,6 +1900,8 @@ static int do_exec(const char *command_line)
                status = 1;
        }
 
+       argv_array_clear(&child_env);
+
        return status;
 }
 
@@ -2668,14 +2673,13 @@ int check_todo_list(void)
 static int rewrite_file(const char *path, const char *buf, size_t len)
 {
        int rc = 0;
-       int fd = open(path, O_WRONLY);
+       int fd = open(path, O_WRONLY | O_TRUNC);
        if (fd < 0)
                return error_errno(_("could not open '%s' for writing"), path);
        if (write_in_full(fd, buf, len) < 0)
                rc = error_errno(_("could not write to '%s'"), path);
-       if (!rc && ftruncate(fd, len) < 0)
-               rc = error_errno(_("could not truncate '%s'"), path);
-       close(fd);
+       if (close(fd) && !rc)
+               rc = error_errno(_("could not close '%s'"), path);
        return rc;
 }