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

Re: Bug encountered while comitting

From
Junio C Hamano <junkio@cox.net>
Date
Mar 25, 2006, 06:17 UTC
Message-ID
<7vwtejxd3u.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<20060325011527.GA23600@spinlock.ch>
Matthias Kestenholz <lists@irregular.ch> writes:
Show 19 quoted lines
> $ sudo chown root .git/objects/*
>
> repeat the modification and commit commands until you get a message
> similar to the following:
>
> unable to write sha1 filename .git/objects/90/b33..: Permission denied
> fatal: 90b33... is not a valid 'tree' object
> unable to write sha1 filename .git/objects/ba/fe4..: Permission denied
> error: file: failed to insert into database
> fatal: Unable to process file file
> etc...
>
> The result of this all is: refs/heads/master might now point to a
> non-existant commit object. Every git command now errors out with:
>
> fatal: bad tree object HEAD
>
> and git-log shows no output (probably since it does not find a
> commit to begin with)

You are right. commit-tree does not seem to check if it successfully wrote the commit object. How about this?

-- >8 --
diff --git a/commit-tree.c b/commit-tree.c
index 88871b0..16c1787 100644
--- a/commit-tree.c
+++ b/commit-tree.c
@@ -125,7 +125,10 @@ int main(int argc, char **argv)
 	while (fgets(comment, sizeof(comment), stdin) != NULL)
 		add_buffer(&buffer, &size, "%s", comment);
 
-	write_sha1_file(buffer, size, "commit", commit_sha1);
-	printf("%s\n", sha1_to_hex(commit_sha1));
-	return 0;
+	if (!write_sha1_file(buffer, size, "commit", commit_sha1)) {
+		printf("%s\n", sha1_to_hex(commit_sha1));
+		return 0;
+	}
+	else
+		return 1;
 }
Previous: Matthias KestenholzNext: Matthias Kestenholz
Message 6 of 7 in “Bug encountered while comitting”
  1. Matthias KestenholzMar 24, 2006
  2. Andreas EricssonMar 24, 2006
  3. Matthias KestenholzMar 25, 2006
  4. Junio C HamanoMar 24, 2006
  5. Matthias KestenholzMar 25, 2006
  6. Junio C HamanoMar 25, 2006
  7. Matthias KestenholzMar 25, 2006

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.