git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] git-add -u paths... now works from subdirectory

From
SZSalikh Zakirov <salikh.zakirov@gmail.com>
Date
Aug 15, 2007, 17:01 UTC
Message-ID
<20070815170143.GA3068@makoto.usen.ad.jp>

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
Next: Junio C Hamano
Message 1 of 2 in “git-add -u paths... now works from subdirectory”
  1. git-add -u paths... now works from subdirectorySalikh Zakirov, Aug 15, 2007
  2. Junio C HamanoAug 15, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.