From: Jeff King <peff@peff.net>
To: "Rhodes, Kate" <masukomi@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [Bug] git add -i fails in multiple ways prior to first commit.
Date: Wed, 13 Feb 2008 05:16:49 -0500 [thread overview]
Message-ID: <20080213101649.GA18444@coredump.intra.peff.net> (raw)
In-Reply-To: <C50196C5-B0C5-4536-AD4A-0F9C553782EE@gmail.com>
On Mon, Feb 11, 2008 at 07:59:46PM -0500, Rhodes, Kate wrote:
> * status fails to report the current status
> * update fails to work at all
Below is a patch to address these two. It works by simulating the
diff as if HEAD contained nothing. The 'diff' command is still broken
(it would need to generate fake diff output against an empty tree).
However, I wonder if this is the best approach. It would be nice if
there were a shorthand for "the empty tree" for diffing, so you could
just diff against that rather than HEAD, and have the regular plumbing
generate.
I suppose we could just create that tree object, though it adds a slight
amount of cruft to the object database.
---
git-add--interactive.perl | 62 ++++++++++++++++++++++++++++++++-------------
1 files changed, 44 insertions(+), 18 deletions(-)
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index 17ca5b8..b9f9abe 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -82,6 +82,17 @@ sub list_untracked {
my $status_fmt = '%12s %12s %s';
my $status_head = sprintf($status_fmt, 'staged', 'unstaged', 'path');
+sub is_initial_commit {
+ return system('git rev-parse HEAD -- >/dev/null 2>&1') != 0;
+}
+
+sub count_blob_lines {
+ my $sha1 = shift;
+ my @lines = run_cmd_pipe(qw(git cat-file blob), $sha1);
+ return scalar(@lines);
+}
+
+
# Returns list of hashes, contents of each of which are:
# VALUE: pathname
# BINARY: is a binary path
@@ -103,27 +114,42 @@ sub list_modified {
return if (!@tracked);
}
- for (run_cmd_pipe(qw(git diff-index --cached
- --numstat --summary HEAD --), @tracked)) {
- if (($add, $del, $file) =
- /^([-\d]+) ([-\d]+) (.*)/) {
- my ($change, $bin);
- if ($add eq '-' && $del eq '-') {
- $change = 'binary';
- $bin = 1;
- }
- else {
- $change = "+$add/-$del";
- }
+ if (is_initial_commit()) {
+ for (run_cmd_pipe(qw(git ls-files --stage --exclude-standard
+ --), @tracked)) {
+ my ($sha1, $file) = /\d+ ([0-9a-f]+) \d\t(.*)/
+ or die "invalid ls-files output: $_";
+ my $n = count_blob_lines($sha1);
$data{$file} = {
- INDEX => $change,
- BINARY => $bin,
+ INDEX => "+$n/-0",
FILE => 'nothing',
- }
+ INDEXADDDEL => 'create',
+ };
}
- elsif (($adddel, $file) =
- /^ (create|delete) mode [0-7]+ (.*)$/) {
- $data{$file}{INDEX_ADDDEL} = $adddel;
+ }
+ else {
+ for (run_cmd_pipe(qw(git diff-index --cached
+ --numstat --summary HEAD --), @tracked)) {
+ if (($add, $del, $file) =
+ /^([-\d]+) ([-\d]+) (.*)/) {
+ my ($change, $bin);
+ if ($add eq '-' && $del eq '-') {
+ $change = 'binary';
+ $bin = 1;
+ }
+ else {
+ $change = "+$add/-$del";
+ }
+ $data{$file} = {
+ INDEX => $change,
+ BINARY => $bin,
+ FILE => 'nothing',
+ }
+ }
+ elsif (($adddel, $file) =
+ /^ (create|delete) mode [0-7]+ (.*)$/) {
+ $data{$file}{INDEX_ADDDEL} = $adddel;
+ }
}
}
--
1.5.4.1.1296.g34f89-dirty
next prev parent reply other threads:[~2008-02-13 10:17 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-12 0:59 [Bug] git add -i fails in multiple ways prior to first commit Rhodes, Kate
2008-02-13 10:16 ` Jeff King [this message]
2008-02-13 10:23 ` Jakub Narebski
2008-02-13 10:37 ` Jeff King
2008-02-13 10:50 ` [PATCH] add--interactive: handle initial commit better Jeff King
2008-02-13 11:25 ` Jeff King
2008-02-13 12:19 ` Johannes Schindelin
2008-02-13 13:11 ` Jakub Narebski
2008-02-13 13:15 ` Jeff King
2008-02-13 13:22 ` Johannes Schindelin
2008-02-13 13:45 ` Johannes Schindelin
2008-02-13 11:30 ` [Bug] git add -i fails in multiple ways prior to first commit Junio C Hamano
2008-02-13 11:34 ` Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080213101649.GA18444@coredump.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=masukomi@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).