From c8fbcb42822373347066c81bcd6c012ecd247486 Mon Sep 17 00:00:00 2001 From: David Caldwell Date: Mon, 22 Dec 2008 15:26:00 -0800 Subject: [PATCH] Add git support! --- commit-patch | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/commit-patch b/commit-patch index d5a6a83..39c7257 100755 --- a/commit-patch +++ b/commit-patch @@ -69,6 +69,11 @@ while (!$vc{name}) { $vc{remove} = 'true'; $vc{patcharg} = '-p1'; $vc{lsdiffarg} = [qw(--strip 1)]; + } elsif (-d "$repo/.git") { + $vc{name} = 'git'; + $vc{message} = sub { ('-m', $_[0]) }; + $vc{message_file} = sub { ('-F', $_[0]) }; + # Git is special cased below. } else { $repo.="/.."; printf("Trying back a dir: $repo, abs:%s\n", abs_path($repo)); @@ -88,6 +93,17 @@ my $patch = shift; die "bad patch file: $!" if -z $patch; die "Invalid message" if defined $message && $message eq ""; +my @message_opt = $message ? $vc{message}->($message) : + $message_filename ? $vc{message_file}->($message_filename) : (); + +# Git pretty much supports what commit-patch does already, so we special case it here. +if ($vc{name} eq 'git') { + run([qw(git diff --cached --quiet)]) or die "The index is not empty. Cowardly refusing to do anything potentially harmful.\n"; + run([qw(git apply --cached), $patch]) or die "Git failed.\n"; + run([qw(git commit), @message_opt]) or die "Git failed.\n"; + exit; +} + my ($lsdiff_out, $err); run ["lsdiff", @{$vc{lsdiffarg}}, $patch], '|', ["sort"], '|', ["uniq"], \$lsdiff_out, \$err or die "lsdiff|sort|unique : $! ($err)"; my @files = split(/\n/, $lsdiff_out); @@ -113,8 +129,6 @@ eval { run(["patch", $vc{patcharg}, "-R"], '<', "working.patch.$$", '>', \$out, '2>', \$err) or die "$out\n$err\n"; run(["patch", $vc{patcharg}], '<', $patch, '>', \$out, '2>', \$err) or die "$out\n$err\n"; # Don't capture stdout or stderr because it can be interactive (cough cough darcs) - my @message_opt = $message ? $vc{message}->($message) : - $message_filename ? $vc{message_file}->($message_filename) : (); run([split(/ /,$vc{commit}), @message_opt, @files],debug => 0) or die "commit failed.\n"; run(["patch", $vc{patcharg}], '<', "non_committed.patch.$$", '>', \$out, '2>', \$err) or die "$out\n$err\n"; }; -- 2.51.2