Merge branch 'jk/maint-add-p-empty' into maint
authorJunio C Hamano <gitster@pobox.com>
Mon, 16 Nov 2009 08:02:44 +0000 (00:02 -0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 16 Nov 2009 08:02:44 +0000 (00:02 -0800)
* jk/maint-add-p-empty:
add-interactive: handle deletion of empty files

1  2 
git-add--interactive.perl
t/t3701-add-interactive.sh
index 69aeaf03ec65922d8a3e5e092fab3d4b6ffcb63e,35f4ef11de581af129deb24cf9160fe817e4551b..8ce1ec92c2b04e1271b3ee1a41a2ac60d2f8aad4
@@@ -259,7 -259,7 +259,7 @@@ sub list_modified 
                @tracked = map {
                        chomp $_;
                        unquote_path($_);
 -              } run_cmd_pipe(qw(git ls-files --exclude-standard --), @ARGV);
 +              } run_cmd_pipe(qw(git ls-files --), @ARGV);
                return if (!@tracked);
        }
  
@@@ -731,14 -731,17 +731,17 @@@ sub parse_diff_header 
  
        my $head = { TEXT => [], DISPLAY => [], TYPE => 'header' };
        my $mode = { TEXT => [], DISPLAY => [], TYPE => 'mode' };
+       my $deletion = { TEXT => [], DISPLAY => [], TYPE => 'deletion' };
  
        for (my $i = 0; $i < @{$src->{TEXT}}; $i++) {
-               my $dest = $src->{TEXT}->[$i] =~ /^(old|new) mode (\d+)$/ ?
-                       $mode : $head;
+               my $dest =
+                  $src->{TEXT}->[$i] =~ /^(old|new) mode (\d+)$/ ? $mode :
+                  $src->{TEXT}->[$i] =~ /^deleted file/ ? $deletion :
+                  $head;
                push @{$dest->{TEXT}}, $src->{TEXT}->[$i];
                push @{$dest->{DISPLAY}}, $src->{DISPLAY}->[$i];
        }
-       return ($head, $mode);
+       return ($head, $mode, $deletion);
  }
  
  sub hunk_splittable {
@@@ -1206,7 -1209,7 +1209,7 @@@ sub patch_update_file 
        my ($ix, $num);
        my $path = shift;
        my ($head, @hunk) = parse_diff($path);
-       ($head, my $mode) = parse_diff_header($head);
+       ($head, my $mode, my $deletion) = parse_diff_header($head);
        for (@{$head->{DISPLAY}}) {
                print;
        }
        if (@{$mode->{TEXT}}) {
                unshift @hunk, $mode;
        }
+       if (@{$deletion->{TEXT}} && !@hunk) {
+               @hunk = ($deletion);
+       }
  
        $num = scalar @hunk;
        $ix = 0;
                        print;
                }
                print colored $prompt_color, $patch_mode_flavour{VERB},
-                 ($hunk[$ix]{TYPE} eq 'mode' ? ' mode change' : ' this hunk'),
+                 ($hunk[$ix]{TYPE} eq 'mode' ? ' mode change' :
+                  $hunk[$ix]{TYPE} eq 'deletion' ? ' deletion' :
+                  ' this hunk'),
                  $patch_mode_flavour{TARGET},
                  " [y,n,q,a,d,/$other,?]? ";
                my $line = prompt_single_character;
index 687bd7ab53397d3bc9d5150bc7cd290efa8ebdbc,aa5909b14c822227bc8d9e7f2425b35458c9be03..d86bc81abfd954194c245e7e180a23f2b9b7c840
@@@ -138,20 -138,6 +138,20 @@@ test_expect_success 'real edit works' 
        test_cmp expected output
  '
  
 +test_expect_success 'skip files similarly as commit -a' '
 +      git reset &&
 +      echo file >.gitignore &&
 +      echo changed >file &&
 +      echo y | git add -p file &&
 +      git diff >output &&
 +      git reset &&
 +      git commit -am commit &&
 +      git diff >expected &&
 +      test_cmp expected output &&
 +      git reset --hard HEAD^
 +'
 +rm -f .gitignore
 +
  if test "$(git config --bool core.filemode)" = false
  then
        say 'skipping filemode tests (filesystem does not properly support modes)'
@@@ -228,4 -214,21 +228,21 @@@ test_expect_success 'add first line wor
        test_cmp expected diff
  '
  
+ cat >expected <<EOF
+ diff --git a/empty b/empty
+ deleted file mode 100644
+ index e69de29..0000000
+ EOF
+ test_expect_success 'deleting an empty file' '
+       git reset --hard &&
+       > empty &&
+       git add empty &&
+       git commit -m empty &&
+       rm empty &&
+       echo y | git add -p empty &&
+       git diff --cached >diff &&
+       test_cmp expected diff
+ '
  test_done