git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Salikh Zakirov <salikh.zakirov@gmail.com>
To: junkio@cox.net
Cc: git@vger.kernel.org
Subject: [PATCH] git-add -u paths... now works from subdirectory
Date: Thu, 16 Aug 2007 02:01:43 +0900	[thread overview]
Message-ID: <20070815170143.GA3068@makoto.usen.ad.jp> (raw)

git-add used to take the path limiters, but always considered them
as top-level paths, and thus didn't work from subdirectories.
However, using git-add -u from subdirectories is very convenient,
especially when development is done from within a subdirectory,
(e.g. for easier grepping), as it allows to use a universal
incantation 'git-add -u .' from anywhere.

Documentaion for git-add does not mention if the paths were supposed to be
relative to current directory of from the top, and the relative paths are far
more intuitive.

Signed-off-by: Salikh Zakirov <salikh@gmail.com>
---

The trivial test added with this patch failed before the patch and passes
after. All tests pass with this modification on my machine (Linux/i686).

Note that the potentially incorrect 'git-add -u ; git commit' behaviour is not
affected by this patch and still can cause horribly incorrect commits.

 builtin-add.c         |    8 ++++----
 t/t2200-add-update.sh |    8 ++++++++
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/builtin-add.c b/builtin-add.c
index 82c806a..a09771f 100644
--- a/builtin-add.c
+++ b/builtin-add.c
@@ -109,12 +109,12 @@ static void update_callback(struct diff_queue_struct *q,
 	}
 }
 
-static void update(int verbose, const char **files)
+static void update(int verbose, const char *prefix, const char **files)
 {
 	struct rev_info rev;
-	init_revisions(&rev, "");
+	init_revisions(&rev, prefix);
 	setup_revisions(0, NULL, &rev, NULL);
-	rev.prune_data = get_pathspec(rev.prefix, files);
+	rev.prune_data = get_pathspec(prefix, files);
 	rev.diffopt.output_format = DIFF_FORMAT_CALLBACK;
 	rev.diffopt.format_callback = update_callback;
 	rev.diffopt.format_callback_data = &verbose;
@@ -216,7 +216,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
 	}
 
 	if (take_worktree_changes) {
-		update(verbose, argv + i);
+		update(verbose, prefix, argv + i);
 		goto finish;
 	}
 
diff --git t/t2200-add-update.sh t/t2200-add-update.sh
index 0a703af..93c007d 100755
--- a/t/t2200-add-update.sh
+++ b/t/t2200-add-update.sh
@@ -35,4 +35,12 @@ test_expect_success 'update did not touch other tracked files' \
 test_expect_success 'update did not touch untracked files' \
   'test "`git diff-files --name-status dir/other`" = ""'
 
+test_expect_success 'more changes' 'echo modified >> dir/sub'
+
+test_expect_success 'update from subdirectory' \
+  '(cd dir; git add -u sub)'
+
+test_expect_success 'update touched correct path' \
+  'test "`git diff-files --name-status dir/sub`" = ""'
+
 test_done
-- 
1.5.3.rc5.24.gac513

             reply	other threads:[~2007-08-15 17:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-15 17:01 Salikh Zakirov [this message]
2007-08-15 22:17 ` [PATCH] git-add -u paths... now works from subdirectory Junio C Hamano

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=20070815170143.GA3068@makoto.usen.ad.jp \
    --to=salikh.zakirov@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    /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).