git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] git-commit: exit non-zero if we fail to commit the index

From
Brandon Casey <casey@nrlssc.navy.mil>
Date
Jan 22, 2008, 19:26 UTC
Message-ID
<47964370.8010300@nrlssc.navy.mil>
In-Reply-To
<7v63xtmc9z.fsf@gitster.siamese.dyndns.org>
---
Junio C Hamano wrote:
Show 14 quoted lines
> Brandon Casey <casey@nrlssc.navy.mil> writes:
> 
>>>  We would need to tell the user that the index is not where
>>> it is when we detect the error, though.
>> The new index we are trying to rename will be deleted.
>> Are you saying we should 
>>   warn the user that the index is now out of sync?
> 
> Yeah, something like that.  But I think that once this happens
> there is no easy and sane recovery path for the user, as the
> most likely cause of the failure there would be the user running
> out of quota, so "git reset HEAD" which may be the way to
> recover from that failure would not have enough room to create a
> new index file anyway.
If you're interested, here's a patch.
-brandon
 builtin-commit.c |   15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/builtin-commit.c b/builtin-commit.c
index 0227936..d8deb1a 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -122,19 +122,23 @@ static void rollback_index_files(void)
 	}
 }
 
-static void commit_index_files(void)
+static int commit_index_files(void)
 {
+	int err = 0;
+
 	switch (commit_style) {
 	case COMMIT_AS_IS:
 		break; /* nothing to do */
 	case COMMIT_NORMAL:
-		commit_lock_file(&index_lock);
+		err = commit_lock_file(&index_lock);
 		break;
 	case COMMIT_PARTIAL:
-		commit_lock_file(&index_lock);
+		err = commit_lock_file(&index_lock);
 		rollback_lock_file(&false_lock);
 		break;
 	}
+
+	return err;
 }
 
 /*
@@ -926,7 +930,10 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 	unlink(git_path("MERGE_HEAD"));
 	unlink(git_path("MERGE_MSG"));
 
-	commit_index_files();
+	if (commit_index_files())
+		die ("Repository has been updated, but unable to write\n"
+		     "new_index file. Check that disk is not full or quota is\n"
+		     "not exceeded, and then \"git reset HEAD\" to recover.");
 
 	rerere();
 	run_hook(get_index_file(), "post-commit", NULL);
-- 
1.5.4.rc4.16.gdd591
Previous: Junio C HamanoNext: Junio C Hamano
Message 5 of 9 in “git-commit: exit non-zero if we fail to commit the index”
  1. git-commit: exit non-zero if we fail to commit the indexBrandon Casey, Jan 17, 2008
  2. Junio C HamanoJan 17, 2008
  3. Brandon CaseyJan 17, 2008
  4. Junio C HamanoJan 17, 2008
  5. git-commit: exit non-zero if we fail to commit the indexBrandon Casey, Jan 22, 2008
  6. Junio C HamanoJan 22, 2008
  7. git-commit: exit non-zero if we fail to commit the indexBrandon Casey, Jan 23, 2008
  8. Junio C HamanoJan 23, 2008
  9. Brandon CaseyJan 23, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.