Make error message after failing commit_lock_file() less confusing

The error message after a failing commit_lock_file() call sometimes looks like this, causing confusion: $ git remote add remote git@server.com/repo.git error: could not commit config file .git/config # Huh?! # I didn't want to commit anything, especially not my config file! While in the narrow context of the lockfile module using the verb 'commit' in the error message makes perfect sense, in the broader context of git the word 'commit' already has a very specific meaning, hence the confusion. Reword these error messages to say "could not write" instead of "could not commit". While at it, include strerror in the error messages after writing the config file or the credential store fails to provide some information about the cause of the failure, and update the style of the error message after writing the reflog fails to match surrounding error messages (i.e. no '' around the pathname and no () around the error description). Signed-off-by: SZEDER Gábor <szeder@ira.uka.de> Signed-off-by: Jeff King <peff@peff.net>

SZEDER Gábor committed Nov 30, 2015 at 12:40 UTC 08a3651fe7f3163acbac461e0daf370329a1d332
4 files changed +8 -5
config.c
+4 -2
@@ -2144,7 +2144,8 @@ int git_config_set_multivar_in_file(const char *config_filename,
2144 }
2145
2146 if (commit_lock_file(lock) < 0) {
2147 - error("could not commit config file %s", config_filename);
2147 + error("could not write config file %s: %s", config_filename,
2148 + strerror(errno));
2149 ret = CONFIG_NO_WRITE;
2150 lock = NULL;
2151 goto out_free;
@@ -2330,7 +2331,8 @@ int git_config_rename_section_in_file(const char *config_filename,
2331 fclose(config_file);
2332 unlock_and_out:
2333 if (commit_lock_file(lock) < 0)
2333 - ret = error("could not commit config file %s", config_filename);
2334 + ret = error("could not write config file %s: %s",
2335 + config_filename, strerror(errno));
2336 out:
2337 free(filename_buf);
2338 return ret;
credential-store.c
+2 -1
@@ -64,7 +64,8 @@ static void rewrite_credential_file(const char *fn, struct credential *c,
64 print_line(extra);
65 parse_credential_file(fn, c, NULL, print_line);
66 if (commit_lock_file(&credential_lock) < 0)
67 - die_errno("unable to commit credential store");
67 + die_errno("unable to write credential store: %s",
68 + strerror(errno));
69 }
70
71 static void store_credential_file(const char *fn, struct credential *c)
fast-import.c
+1 -1
@@ -1821,7 +1821,7 @@ static void dump_marks(void)
1821
1822 dump_marks_helper(f, 0, marks);
1823 if (commit_lock_file(&mark_lock)) {
1824 - failure |= error("Unable to commit marks file %s: %s",
1824 + failure |= error("Unable to write file %s: %s",
1825 export_marks_file, strerror(errno));
1826 return;
1827 }
refs.c
+1 -1
@@ -4643,7 +4643,7 @@ int reflog_expire(const char *refname, const unsigned char *sha1,
4643 get_lock_file_path(lock->lk));
4644 rollback_lock_file(&reflog_lock);
4645 } else if (commit_lock_file(&reflog_lock)) {
4646 - status |= error("unable to commit reflog '%s' (%s)",
4646 + status |= error("unable to write reflog %s: %s",
4647 log_file, strerror(errno));
4648 } else if (update && commit_ref(lock)) {
4649 status |= error("couldn't set %s", lock->ref_name);