Skip to contentSkip to conversation

describe: setup working tree for --dirty

PATCH Superseded Sebastian Staudt 3 participants 8 messages Feb 1, 2019 – Feb 3, 2019

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/2 describe: setup working tree for --dirty

We don't use NEED_WORK_TREE when running the git-describe builtin, since you should be able to describe a commit even in a bare repository. However, the --dirty flag does need a working tree. Since we don't call setup_work_tree(), it uses whatever directory we happen to be in. That's unlikely to match our index, meaning we'd say "dirty" even when the real working tree is clean.

We can fix that by calling setup_work_tree() once we know that the user has asked for --dirty.

The --broken option also needs a working tree. But because its implementation calls git-diff-index we don‘t have to setup the working tree in the git-describe process.

---
 builtin/describe.c  |  1 +
 t/t6120-describe.sh | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+)
builtin/describe.c +1 -0
index cc118448ee..b5b7abdc8f 100644
@@ -629,6 +629,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
 			struct argv_array args = ARGV_ARRAY_INIT;
 			int fd, result;
 
+			setup_work_tree();
 			read_cache();
 			refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED,
 				      NULL, NULL, NULL);
t/t6120-describe.sh +33 -0
index d639d94696..7cfed77c52 100755
@@ -145,14 +145,38 @@ check_describe A-* HEAD
 
 check_describe "A-*[0-9a-f]" --dirty
 
+test_expect_success 'describe --dirty with --work-tree' '
+	(
+		cd "$TEST_DIRECTORY" &&
+		git --git-dir "$TRASH_DIRECTORY/.git" --work-tree "$TRASH_DIRECTORY" describe --dirty >"$TRASH_DIRECTORY/out"
+	) &&
+	grep "^A-[1-9][0-9]\?-g[0-9a-f]\+$" out
+'
+
 test_expect_success 'set-up dirty work tree' '
 	echo >>file
 '
 
 check_describe "A-*[0-9a-f]-dirty" --dirty
 
+test_expect_success 'describe --dirty with --work-tree' '
+	(
+		cd "$TEST_DIRECTORY" &&
+		git --git-dir "$TRASH_DIRECTORY/.git" --work-tree "$TRASH_DIRECTORY" describe --dirty >"$TRASH_DIRECTORY/out"
+	) &&
+	grep "^A-[1-9][0-9]\?-g[0-9a-f]\+-dirty$" out
+'
+
 check_describe "A-*[0-9a-f].mod" --dirty=.mod
 
+test_expect_success 'describe --dirty=.mod with --work-tree' '
+	(
+		cd "$TEST_DIRECTORY" &&
+		git --git-dir "$TRASH_DIRECTORY/.git" --work-tree "$TRASH_DIRECTORY" describe --dirty=.mod >"$TRASH_DIRECTORY/out"
+	) &&
+	grep "^A-[1-9][0-9]\?-g[0-9a-f]\+.mod$" out
+'
+
 test_expect_success 'describe --dirty HEAD' '
 	test_must_fail git describe --dirty HEAD
 '
@@ -303,8 +327,17 @@ test_expect_success 'describe chokes on severely broken submodules' '
 	mv .git/modules/sub1/ .git/modules/sub_moved &&
 	test_must_fail git describe --dirty
 '
+
 test_expect_success 'describe ignoring a broken submodule' '
 	git describe --broken >out &&
+	grep broken out
+'
+
+test_expect_success 'describe with --work-tree ignoring a broken submodule' '
+	(
+		cd "$TEST_DIRECTORY" &&
+		git --git-dir "$TRASH_DIRECTORY/.git" --work-tree "$TRASH_DIRECTORY" describe --broken >"$TRASH_DIRECTORY/out"
+	) &&
 	test_when_finished "mv .git/modules/sub_moved .git/modules/sub1" &&
 	grep broken out
 '
Signature · 1 line
2.20.1
#1 lore raw

PATCH v4 2/2 t6120: test for describe with a bare repository

This ensures that nothing breaks the basic functionality of describe for bare repositories. Please note that --broken and --dirty need a working tree.

---
 t/t6120-describe.sh | 5 +++++
 1 file changed, 5 insertions(+)
t/t6120-describe.sh +5 -0
index 7cfed77c52..ea2c3dbe1c 100755
@@ -418,4 +418,9 @@ test_expect_success 'describe complains about missing object' '
 	test_must_fail git describe $ZERO_OID
 '
 
+test_expect_success 'describe works from outside repo using --git-dir' ' 
+  git clone --bare "$TRASH_DIRECTORY" "$TRASH_DIRECTORY/bare" &&
+  git --git-dir "$TRASH_DIRECTORY/bare" describe
+'
+
 test_done
Signature · 1 line
2.20.1
#2 lore raw

Re: [PATCH v4 2/2] t6120: test for describe with a bare repository

Quoted 14 lines · Sebastian Staudt

This ensures that nothing breaks the basic functionality of describe for bare repositories. Please note that --broken and --dirty need a working tree.

---
 t/t6120-describe.sh | 5 +++++
 1 file changed, 5 insertions(+)
t/t6120-describe.sh +0 -0
index 7cfed77c52..ea2c3dbe1c 100755

t/t6120-describe.sh test_expect_success 'describe complains about missing object' ' · line 424

Quoted 7 lines
t/t6120-describe.sh +4 -0
@@ -418,4 +418,9 @@ test_expect_success 'describe complains about missing object' '
 	test_must_fail git describe $ZERO_OID
 '
 
+test_expect_success 'describe works from outside repo using --git-dir' ' 
+  git clone --bare "$TRASH_DIRECTORY" "$TRASH_DIRECTORY/bare" &&
+  git --git-dir "$TRASH_DIRECTORY/bare" describe
+'

OK, it demonstrates that the command exits with status 0. Do we want to validate its output, too?

#4 lore raw
In reply to Sebastian Staudt
Quoted 11 lines · Sebastian Staudt

We don't use NEED_WORK_TREE when running the git-describe builtin, since you should be able to describe a commit even in a bare repository. However, the --dirty flag does need a working tree. Since we don't call setup_work_tree(), it uses whatever directory we happen to be in. That's unlikely to match our index, meaning we'd say "dirty" even when the real working tree is clean.

---

t/t6120-describe.sh check_describe A-* HEAD · line 151

Quoted 7 lines
t/t6120-describe.sh +6 -0
@@ -145,14 +145,38 @@ check_describe A-* HEAD
+test_expect_success 'describe --dirty with --work-tree' '
+       [...]
+'
 
+test_expect_success 'describe --dirty with --work-tree' '
+       [...]
+'

Can you give these two new tests different titles to make it easier to narrow down a problem to one or the other if one of them does fail? Perhaps the second test could be titled:

    test_expect_success 'describe --dirty with dirty --work-tree' '

or something.

#7 lore raw
In reply to Sebastian Staudt
Quoted 7 lines · Sebastian Staudt

We don't use NEED_WORK_TREE when running the git-describe builtin, since you should be able to describe a commit even in a bare repository. However, the --dirty flag does need a working tree. Since we don't call setup_work_tree(), it uses whatever directory we happen to be in. That's unlikely to match our index, meaning we'd say "dirty" even when the real working tree is clean.

Quoted 6 lines

We can fix that by calling setup_work_tree() once we know that the user has asked for --dirty.

The --broken option also needs a working tree. But because its implementation calls git-diff-index we don‘t have to setup the working tree in the git-describe process.

Very nicely described.

Quoted 13 lines
---
 builtin/describe.c  |  1 +
 t/t6120-describe.sh | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+)
builtin/describe.c +0 -0
index cc118448ee..b5b7abdc8f 100644

builtin/describe.c int cmd_describe(int argc, const char **argv, const char *prefix) · line 635

Quoted 7 lines
builtin/describe.c +1 -0
@@ -629,6 +629,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
 			struct argv_array args = ARGV_ARRAY_INIT;
 			int fd, result;
 
+			setup_work_tree();
 			read_cache();
 			refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED,
 				      NULL, NULL, NULL);

And the implementation is as promised in the proposed log message. Quite straight-forward and obviously right ;-)

Quoted 6 lines
t/t6120-describe.sh +0 -0
index d639d94696..7cfed77c52 100755
@@ -145,14 +145,38 @@ check_describe A-* HEAD
 

t/t6120-describe.sh check_describe A-* HEAD · line 155

Quoted 10 lines
t/t6120-describe.sh +8 -0
 check_describe "A-*[0-9a-f]" --dirty
 
+test_expect_success 'describe --dirty with --work-tree' '
+	(
+		cd "$TEST_DIRECTORY" &&
+		git --git-dir "$TRASH_DIRECTORY/.git" --work-tree "$TRASH_DIRECTORY" describe --dirty >"$TRASH_DIRECTORY/out"
+	) &&
+	grep "^A-[1-9][0-9]\?-g[0-9a-f]\+$" out
+'
+

Without the fix to the code, this test piece fails with "-dirty" suffix in 'out'. Good.

t/t6120-describe.sh check_describe A-* HEAD · line 168

Quoted 7 lines
t/t6120-describe.sh +7 -0
+test_expect_success 'describe --dirty with --work-tree' '
+	(
+		cd "$TEST_DIRECTORY" &&
+		git --git-dir "$TRASH_DIRECTORY/.git" --work-tree "$TRASH_DIRECTORY" describe --dirty >"$TRASH_DIRECTORY/out"
+	) &&
+	grep "^A-[1-9][0-9]\?-g[0-9a-f]\+-dirty$" out
+'

This succeeds with or without the fix to the code; the buggy behaviour was to claim "-dirty"-ness when the working tree files are clean. This new test is not about that buggy behaviour. It is rather about the updated code does not mistakenly claim cleanness in a dirty working tree. Good.

t/t6120-describe.sh check_describe A-* HEAD · line 179

Quoted 10 lines
t/t6120-describe.sh +8 -0
 check_describe "A-*[0-9a-f].mod" --dirty=.mod
 
+test_expect_success 'describe --dirty=.mod with --work-tree' '
+	(
+		cd "$TEST_DIRECTORY" &&
+		git --git-dir "$TRASH_DIRECTORY/.git" --work-tree "$TRASH_DIRECTORY" describe --dirty=.mod >"$TRASH_DIRECTORY/out"
+	) &&
+	grep "^A-[1-9][0-9]\?-g[0-9a-f]\+.mod$" out
+'
+

Likewise.

Quoted 8 lines
t/t6120-describe.sh +1 -0
 test_expect_success 'describe --dirty HEAD' '
 	test_must_fail git describe --dirty HEAD
 '
@@ -303,8 +327,17 @@ test_expect_success 'describe chokes on severely broken submodules' '
 	mv .git/modules/sub1/ .git/modules/sub_moved &&
 	test_must_fail git describe --dirty
 '
+

t/t6120-describe.sh test_expect_success 'describe chokes on severely broken submodules' ' · line 340

Quoted 10 lines
t/t6120-describe.sh +8 -0
 test_expect_success 'describe ignoring a broken submodule' '
 	git describe --broken >out &&
+	grep broken out
+'
+
+test_expect_success 'describe with --work-tree ignoring a broken submodule' '
+	(
+		cd "$TEST_DIRECTORY" &&
+		git --git-dir "$TRASH_DIRECTORY/.git" --work-tree "$TRASH_DIRECTORY" describe --broken >"$TRASH_DIRECTORY/out"
+	) &&

OK, this checks the same repository as the existing test does, but does so from outside the repository.

Looks good.

Quoted 3 lines
t/t6120-describe.sh +0 -0
 	test_when_finished "mv .git/modules/sub_moved .git/modules/sub1" &&
 	grep broken out
 '
#3 lore raw

Re: [PATCH v4 2/2] t6120: test for describe with a bare repository

In reply to Junio C Hamano

Am Fr., 1. Feb. 2019 um 19:53 Uhr schrieb Junio C Hamano <[email protected]>:

Quoted 20 lines
Quoted 17 lines · Sebastian Staudt

This ensures that nothing breaks the basic functionality of describe for bare repositories. Please note that --broken and --dirty need a working tree.

---
 t/t6120-describe.sh | 5 +++++
 1 file changed, 5 insertions(+)
t/t6120-describe.sh +0 -0
index 7cfed77c52..ea2c3dbe1c 100755
@@ -418,4 +418,9 @@ test_expect_success 'describe complains about missing object' '
      test_must_fail git describe $ZERO_OID
 '
 
Quoted 7 lines

t/t6120-describe.sh test_expect_success 'describe complains about missing object' ' · line 424

Quoted 4 lines
t/t6120-describe.sh +4 -0
+test_expect_success 'describe works from outside repo using --git-dir' '
+  git clone --bare "$TRASH_DIRECTORY" "$TRASH_DIRECTORY/bare" &&
+  git --git-dir "$TRASH_DIRECTORY/bare" describe
+'

OK, it demonstrates that the command exits with status 0. Do we want to validate its output, too?

It won‘t hurt.
I‘ll move this test further up, so it is executed when the working tree is still clean. That way we can use the same regex as for the other checks.

Thanks.

#5 lore raw
In reply to Eric Sunshine

Am Fr., 1. Feb. 2019 um 21:12 Uhr schrieb Eric Sunshine <[email protected]>:

Quoted 25 lines · Sebastian Staudt
Quoted 11 lines

We don't use NEED_WORK_TREE when running the git-describe builtin, since you should be able to describe a commit even in a bare repository. However, the --dirty flag does need a working tree. Since we don't call setup_work_tree(), it uses whatever directory we happen to be in. That's unlikely to match our index, meaning we'd say "dirty" even when the real working tree is clean.

---

t/t6120-describe.sh check_describe A-* HEAD · line 151

Quoted 7 lines
t/t6120-describe.sh +6 -0
@@ -145,14 +145,38 @@ check_describe A-* HEAD
+test_expect_success 'describe --dirty with --work-tree' '
+       [...]
+'
 
+test_expect_success 'describe --dirty with --work-tree' '
+       [...]
+'

Can you give these two new tests different titles to make it easier to narrow down a problem to one or the other if one of them does fail? Perhaps the second test could be titled:

Quoted 3 lines
    test_expect_success 'describe --dirty with dirty --work-tree' '

or something.

Thanks, didn‘t notice this.
I‘d use a suffix (dirty) for my test titles. But this won‘t work for tests using check_describe(). Any objections?

#6 lore raw
Quoted 16 lines · Sebastian Staudt

Am Fr., 1. Feb. 2019 um 21:12 Uhr schrieb Eric Sunshine <[email protected]>:

Quoted 14 lines · Sebastian Staudt

t/t6120-describe.sh check_describe A-* HEAD · line 150

Quoted 8 lines
t/t6120-describe.sh +6 -0
@@ -145,14 +145,38 @@ check_describe A-* HEAD
+test_expect_success 'describe --dirty with --work-tree' '
+       [...]
+'
+test_expect_success 'describe --dirty with --work-tree' '
+       [...]
+'

Can you give these two new tests different titles to make it easier to narrow down a problem to one or the other if one of them does fail? Perhaps the second test could be titled:

Quoted 7 lines
Quoted 3 lines
    test_expect_success 'describe --dirty with dirty --work-tree' '

or something.

Thanks, didn‘t notice this.
I‘d use a suffix (dirty) for my test titles. But this won‘t work for tests using check_describe(). Any objections?

I have no objections to using suffix "(dirty)".

It's true that there are a few duplicate test titles due to check_describe() invocations, however, this patch isn't introducing any new callers, so it's not strictly a concern of this series. If you did want to address that issue, one possibility would be to add a 'title' argument to check_describe() and adjust callers to use a unique title, however, such a change would not be part of this particular patch, and I'm not convinced that it's even worth the effort and churn at this point.