threads / patch / 12214

patchTest case for a problem with git add -u from subdirectory

Subject: [PATCH] Test case for a problem with git add -u from subdirectory

## tl;dr

3 messages between Feb 20, 2008 and Feb 20, 2008. Diffs are folded; open one to read it.

replies: 2people: 2as markdown or json

Pekka Kaitaniemi· Feb 20, 2008, 14:32 UTC · lore

Manual page for "git-add -u" says: Update only files that git already knows about. This is similar to what "git commit -a" does in preparation for making a commit, except that the update is limited to paths specified on the command line. If no paths are specified, all tracked files are updated.

The key sentence being: "If no paths are specified, all tracked files are updated." If one modifies a file in subdir1, then goes to subdir2 and performs "git add -u" the modified file in subdir1 is not added to the index. This test case demonstrates the problem.

Signed-off-by: Pekka Kaitaniemi <kaitanie@cc.helsinki.fi>
---

I found a possible problem in "git add -u" command without any paths. Modified files located in a different subdirectory are not added to the index even though the documentation says that in this case all tracked files should be. Maybe this is caused by a bug in "git add"? Or is the problem in the documentation?

In any case, this patch contains a test case that demonstrates the problem.

 t/t2200-add-update.sh |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
Show changes to t/t2200-add-update.sh +16 −0
diff --git a/t/t2200-add-update.sh b/t/t2200-add-update.sh
index 24f892f..5815ec5 100755
--- a/t/t2200-add-update.sh
+++ b/t/t2200-add-update.sh
@@ -80,6 +80,22 @@ test_expect_success 'change gets noticed' '
 
 '
 
+test_expect_success 'update from a different subdirectory' '
+	(
+		cd dir1 &&
+		echo addmore >sub2 &&
+                cd ../dir2 &&
+                git add -u
+	)
+
+'
+
+test_expect_success 'change gets noticed' '
+
+	test "$(git diff-files --name-status dir1)" = ""
+
+'
+
 test_expect_success 'replace a file with a symlink' '
 
 	rm foo &&
-- 
1.5.4.2
Junio C Hamano· Feb 20, 2008, 18:37 UTC · re: Pekka Kaitaniemi · lore

Re: [PATCH] Test case for a problem with git add -u from subdirectory

Pekka Kaitaniemi <kaitanie@cc.helsinki.fi> writes:
> The key sentence being: "If no paths are specified, all tracked files
> are updated."

My recollection is that the current behaviour was requested specifically by the users. Although I do not remember offhand, the first implementation might have even been doing the whole tree unconditionally, and surprised users by stepping outside of the current subdirectory.

Sometimes I am annoyed that it does not do the whole tree (i.e. you have to go to the top), but some other times (which happens to be majority for me but it would depend on the project) I find the current behaviour a lot more convenient, and personally I do not think it is a good idea to change the current behaviour.

Please send in documentation clarifications.
Pekka Kaitaniemi· Feb 20, 2008, 19:31 UTC · re: Junio C Hamano · lore

Re: [PATCH] Test case for a problem with git add -u from subdirectory

On Wed, Feb 20, 2008 at 10:37:36AM -0800, Junio C Hamano wrote:
Show 10 quoted lines
> Pekka Kaitaniemi <kaitanie@cc.helsinki.fi> writes:
> 
> > The key sentence being: "If no paths are specified, all tracked files
> > are updated."
> 
> My recollection is that the current behaviour was requested
> specifically by the users.  Although I do not remember offhand,
> the first implementation might have even been doing the whole
> tree unconditionally, and surprised users by stepping outside of
> the current subdirectory.

I was a bit confused whether it was a feature or a bug and since the documentation seemed to indicate that "git add -u" should add everything I suspected that it was a bug. Anyways, thanks for the clarification.

Show 6 quoted lines
> Sometimes I am annoyed that it does not do the whole tree
> (i.e. you have to go to the top), but some other times (which
> happens to be majority for me but it would depend on the
> project) I find the current behaviour a lot more convenient, and
> personally I do not think it is a good idea to change the
> current behaviour.

I agree. Changing the behaviour is not good since it was requested by users and implemented intentionally.

If adding all tracked files in the whole tree to the index is needed, then maybe it would be useful to add a new flag to git-add? Something like -a (as in all), or -U (really update the whole tree) might be useful option. But then again, the difference between them should also be documented clearly.

> Please send in documentation clarifications.
OK, I'll prepare a patch.
Pekka

← back to recent threads