Author: adsb
Date: 2008-11-04 20:55:05 +0000 (Tue, 04 Nov 2008)
New Revision: 1701

Modified:
   trunk/debian/changelog
   trunk/scripts/debcommit.pl
Log:
Allow a newly initialised (i.e. containing no HEAD) git tree to be
committed to. Based on a patch by Eric Gerlach. (Closes: #497995)

Modified: trunk/debian/changelog
===================================================================
--- trunk/debian/changelog      2008-11-04 20:39:39 UTC (rev 1700)
+++ trunk/debian/changelog      2008-11-04 20:55:05 UTC (rev 1701)
@@ -31,6 +31,8 @@
   * debcommit:
     + Allow --release to be combined with --edit or --confirm. Based on
       a patch by Eric Gerlach. (Closes: #497988)
+    + Allow a newly initialised (i.e. containing no HEAD) git tree to be
+      committed to. Based on a patch by Eric Gerlach. (Closes: #497995)
   * debdiff: Correctly handle hyphenated distribution names when generating
     a diff against the previous version of the package. (Closes: #503950)
   * getbuildlog:

Modified: trunk/scripts/debcommit.pl
===================================================================
--- trunk/scripts/debcommit.pl  2008-11-04 20:39:39 UTC (rev 1700)
+++ trunk/scripts/debcommit.pl  2008-11-04 20:55:05 UTC (rev 1701)
@@ -612,10 +612,15 @@
        } elsif ($prog eq 'bzr') {
            @diffcmd = ($prog, 'diff', '--diff-options', '-wu');
        } elsif ($prog eq 'git') {
-           if ($all) {
-               @diffcmd = ('git', 'diff', '-w', '--no-color');
+           if (git_repo_has_commits()) {
+               if ($all) {
+                   @diffcmd = ('git', 'diff', '-w', '--no-color');
+               } else {
+                   @diffcmd = ('git', 'diff', '-w', '--cached', '--no-color');
+               }
            } else {
-               @diffcmd = ('git', 'diff', '-w', '--cached', '--no-color');
+               # No valid head!  Rather than fail, cheat and use 'diff'
+               @diffcmd = ('diff', '-u', '/dev/null');
            }
        } elsif ($prog eq 'svn') {
            @diffcmd = ($prog, 'diff', '--diff-cmd', '/usr/bin/diff', 
'--extensions', '-wu');
@@ -734,6 +739,12 @@
     chomp $message;
     return ($message, $mtime != $newmtime);
 }
+
+sub git_repo_has_commits {
+    my $command = "git rev-parse --verify --quiet HEAD >/dev/null";
+    system $command;
+    return ($? >> 8 == 0) ? 1 : 0;
+}
 =head1 LICENSE
 
 This code is copyright by Joey Hess <[EMAIL PROTECTED]>, all rights reserved.



-- 
To unsubscribe, send mail to [EMAIL PROTECTED]

Reply via email to