git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] git-add -u paths... now works from subdirectory
@ 2007-08-15 17:01 Salikh Zakirov
  2007-08-15 22:17 ` Junio C Hamano
  0 siblings, 1 reply; 2+ messages in thread
From: Salikh Zakirov @ 2007-08-15 17:01 UTC (permalink / raw)
  To: junkio; +Cc: git

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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-08-15 22:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-15 17:01 [PATCH] git-add -u paths... now works from subdirectory Salikh Zakirov
2007-08-15 22:17 ` Junio C Hamano

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).