@matheusbsbs / matheus-bagliano / commits / d616a23964
Fork 0

builtin-commit: fix amending of the initial commit

When amending initial commit without editor, the command incorrectly barfed because the check to see if there is anything to commit referenced the non-existent HEAD^1. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Dec 22, 2007 at 19:22 UTC d616a2396456fdb6679efa0c0bee301aeb606ca8
1 file changed +4 -4
builtin-commit.c
+4 -4
@@ -374,7 +374,7 @@ static int prepare_log_message(const char *index_file, const char *prefix)
374
375 if (no_edit) {
376 struct rev_info rev;
377 - unsigned char sha1[40];
377 + unsigned char sha1[20];
378 const char *parent = "HEAD";
379
380 fclose(fp);
@@ -382,12 +382,12 @@ static int prepare_log_message(const char *index_file, const char *prefix)
382 if (!active_nr && read_cache() < 0)
383 die("Cannot read index");
384
385 - if (get_sha1("HEAD", sha1) != 0)
386 - return !!active_nr;
387 -
385 if (amend)
386 parent = "HEAD^1";
387
388 + if (get_sha1(parent, sha1))
389 + return !!active_nr;
390 +
391 init_revisions(&rev, "");
392 rev.abbrev = 0;
393 setup_revisions(0, NULL, &rev, parent);