git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Marc Weber <marco-oweber@gmx.de>
Cc: git@vger.kernel.org
Subject: Re: git add --patch newfile doesn't add newfile to cache ?
Date: Mon, 20 Oct 2008 19:50:50 -0400	[thread overview]
Message-ID: <20081020235049.GA23120@coredump.intra.peff.net> (raw)
In-Reply-To: <20081020143636.GB3988@gmx.de>

On Mon, Oct 20, 2008 at 04:36:36PM +0200, Marc Weber wrote:

> Is this desired behaviour?
> [...]
>         git init
>         echo test > test
>         git add --patch test
>         echo "running status, nothing has been added"
>         git status

I think your example makes sense, but nobody ever really tried it
before. I use "git add -p" all the time, but almost always when I am
adding a new file, I add the whole contents.

I think there are two ways to go about fixing it:

  - in git-add--interactive.perl, the function patch_update_cmd
    explicitly looks at the list of modified files. It would have to
    also check for untracked files, which is easy. But we also need to
    keep track of which files are modified and which are untracked
    through the whole patching procedure, which is a bit more invasive.

  - the recently-added "git add -N" adds an empty file into the index,
    at which point we could add content in the normal way. So:

      git add -N test
      git add -p test

    should just work (but obviously requires two steps from the user).
    You could do something more automatic like the patch below, but I
    think the semantics aren't quite right. If you stage nothing for a
    newly added file, then you still end up with an empty version of the
    staged file in the index. I would expect the semantics to be:

      1. if you stage any content, then the file is added to the index
         with that content

      2. if you stage no content, then the file remains untracked

---
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index da768ee..72f8a67 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -811,6 +811,12 @@ EOF
 }
 
 sub patch_update_cmd {
+	my @new = list_untracked();
+	if (@new) {
+		system(qw(git add -N), @new)
+			and die "git add reported failure";
+	}
+
 	my @mods = grep { !($_->{BINARY}) } list_modified('file-only');
 	my @them;
 

  reply	other threads:[~2008-10-20 23:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-20 14:36 git add --patch newfile doesn't add newfile to cache ? Marc Weber
2008-10-20 23:50 ` Jeff King [this message]
2008-10-22 13:12   ` Marc Weber
2008-10-22 13:29     ` 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=20081020235049.GA23120@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=marco-oweber@gmx.de \
    /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).