Skip to contentSkip to conversation

Add tests for describe with --work-tree

PATCH In review Sebastian Staudt 4 participants 15 messages Jan 29, 2019 – Jan 30, 2019

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/3 Add tests for describe with --work-tree

The dirty ones are already passing, but just because describe is comparing with the wrong working tree.

---
 t/t6120-describe.sh | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
t/t6120-describe.sh +33 -0
index d639d94696..c863c4f600 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-\d\+-g[0-9a-f]\+' '$TRASH_DIRECTORY/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-\d\+-g[0-9a-f]\+-dirty' '$TRASH_DIRECTORY/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-\d\+-g[0-9a-f]\+.mod' '$TRASH_DIRECTORY/out'
+"
+
 test_expect_success 'describe --dirty HEAD' '
 	test_must_fail git describe --dirty HEAD
 '
@@ -303,12 +327,21 @@ 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 &&
 	test_when_finished "mv .git/modules/sub_moved .git/modules/sub1" &&
 	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'
+	) &&
+	grep broken '$TRASH_DIRECTORY/out'
+"
+
 test_expect_success 'describe a blob at a directly tagged commit' '
 	echo "make it a unique blob" >file &&
 	git add file && git commit -m "content in file" &&
Signature · 1 line
2.20.1
#1 lore raw

PATCH v3 2/3 Setup working tree in describe

This ensures the given working tree is used for --dirty.

The implementation of --broken uses diff-index which calls setup_work_tree() itself.

---
 builtin/describe.c | 1 +
 1 file changed, 1 insertion(+)
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);
Signature · 1 line
2.20.1
#8 lore raw

PATCH v3 3/3 Add test for describe with a bare repository

In reply to 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 +5 -0
index c863c4f600..f7539a2650 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
#11 lore raw
In reply to Sebastian Staudt
Quoted 13 lines · Sebastian Staudt

The dirty ones are already passing, but just because describe is comparing with the wrong working tree.

---
 t/t6120-describe.sh | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
t/t6120-describe.sh +0 -0
index d639d94696..c863c4f600 100755

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

Quoted 4 lines
t/t6120-describe.sh +1 -0
@@ -145,14 +145,38 @@ check_describe A-* HEAD
 
 check_describe "A-*[0-9a-f]" --dirty
 
+test_expect_success 'describe --dirty with --work-tree' "

This should be marked as test_expect_failure, I think, because it does not yet pass (and then flipped s/failure/success/ in the next patch).

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

Quoted 4 lines
t/t6120-describe.sh +4 -0
+	(
+		cd '$TEST_DIRECTORY' &&
+		git --git-dir '$TRASH_DIRECTORY/.git' --work-tree '$TRASH_DIRECTORY' describe --dirty >'$TRASH_DIRECTORY/out'
+	) &&

The quoting you've done here is unusual for our test suite, and not quite as robust. You've put the whole test snippet into double-quotes, which means that $TRASH_DIRECTORY, etc, will be expanded before we eval the code.

By putting single-quotes around $TRASH_DIRECTORY, that makes it work when the path contains a space. But it would fail if somebody's filesystem path contains a single-quote.

The usual style is to put the whole snippet into single-quotes, and then double-quote as appropriate within it. Like:

test_expect_failure 'describe --dirty with --work-tree' '

	(
		cd "$TEST_DIRECTORY" &&
		git --git-dir "$TRASH_DIRECTORY/.git" ...etc

Those variables will be expanded when test_expect_failure eval's the snippet.

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

Quoted 1 line
t/t6120-describe.sh +1 -0
+	grep 'A-\d\+-g[0-9a-f]\+' '$TRASH_DIRECTORY/out'

Using "\d" isn't portable.

This regex is pretty broad. What are we checking here? If I understand the previous discussion, we just care that it doesn't have "dirty" in it, right? I don't think this regex does that, because it doesn't anchor the end of string.

If that's indeed what we're checking, then an easier check is perhaps:

! grep dirty ...

As a side note, you can also shorten your references to "out" by referring to it from the trash directory itself. I.e.:

(

	cd "$TEST_DIRECTORY" &&
	git --git-dir="$TRASH_DIRECTORY/.git" --work-tree "$TRASH_DIRECTORY" \
	  describe --dirty

) >out &&
! grep dirty out

Same thing, but IMHO a little easier to read.

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

Quoted 4 lines
t/t6120-describe.sh +1 -0
 check_describe "A-*[0-9a-f]-dirty" --dirty
 
+test_expect_success 'describe --dirty with --work-tree' "
[...]

Same comments apply to the other blocks you added.

Other than those mechanical things, though, what the tests are actually trying to do seems quite reasonable to me.

-Peff

#2 lore raw

Re: [PATCH v3 2/3] Setup working tree in describe

In reply to Sebastian Staudt
Quoted 1 line · Sebastian Staudt

Subject: Re: [PATCH v3 2/3] Setup working tree in describe

We usually write subjects as "area: do some thing" which is a little easier when scanning big lists of "git log --oneline".

I think it's key, too, that we only do this for the --dirty case, not always. So maybe:

describe: setup working tree for --dirty

or something?

Quoted 1 line

This ensures the given working tree is used for --dirty.

There's been a lot of digging and discussion on the list about what happens if we don't do this. Could we summarize it here?

Perhaps:

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.

Quoted 2 lines

The implementation of --broken uses diff-index which calls setup_work_tree() itself.

If I hadn't just read the rest of the thread, I'd probably wonder why we are talking about --broken at all. Maybe:

The --broken option similarly needs a working tree. But because the current implementation calls an external diff-index to do the work, we don't have to bother setting up the working tree in the git-describe process.

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

Quoted 12 lines
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);

The patch itself looks good. :)

-Peff

#9 lore raw

Re: [PATCH v3 3/3] Add test for describe with a bare repository

In reply to Sebastian Staudt
Quoted 3 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.

Makes sense.

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
+"

What the test is doing seems sane, but the same quoting comments from the earlier patch apply.

-Peff

#3 lore raw

Re: [PATCH v3 2/3] Setup working tree in describe

In reply to Jeff King
Quoted 7 lines · Jeff King
Quoted 1 line · Sebastian Staudt

Subject: Re: [PATCH v3 2/3] Setup working tree in describe

We usually write subjects as "area: do some thing" which is a little easier when scanning big lists of "git log --oneline".

Quoted 6 lines

I think it's key, too, that we only do this for the --dirty case, not always. So maybe:

describe: setup working tree for --dirty

or something?

Thanks as always for being an excellent reviewer who not just reviews but also gives good suggestions.

Quoted 44 lines
Quoted 1 line

This ensures the given working tree is used for --dirty.

There's been a lot of digging and discussion on the list about what happens if we don't do this. Could we summarize it here?

Perhaps:

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.

Quoted 2 lines

The implementation of --broken uses diff-index which calls setup_work_tree() itself.

If I hadn't just read the rest of the thread, I'd probably wonder why we are talking about --broken at all. Maybe:

The --broken option similarly needs a working tree. But because the current implementation calls an external diff-index to do the work, we don't have to bother setting up the working tree in the git-describe process.

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

Quoted 12 lines
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);

The patch itself looks good. :)

-Peff

#12 lore raw
In reply to Jeff King
Quoted 10 lines · Jeff King

The usual style is to put the whole snippet into single-quotes, and then double-quote as appropriate within it. Like:

test_expect_failure 'describe --dirty with --work-tree' '

	(
		cd "$TEST_DIRECTORY" &&
		git --git-dir "$TRASH_DIRECTORY/.git" ...etc

Those variables will be expanded when test_expect_failure eval's the snippet.

Good.

Quoted 3 lines

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

Quoted 1 line
t/t6120-describe.sh +1 -0
+	grep 'A-\d\+-g[0-9a-f]\+' '$TRASH_DIRECTORY/out'

Using "\d" isn't portable.

True, but not just \d. I think using \ before special characters to force an otherwise basic regular expression to be ERE (i.e. \+ at the end) is a GNUism.

Quoted 8 lines

This regex is pretty broad. What are we checking here? If I understand the previous discussion, we just care that it doesn't have "dirty" in it, right? I don't think this regex does that, because it doesn't anchor the end of string.

If that's indeed what we're checking, then an easier check is perhaps:

! grep dirty ...

Good.

#4 lore raw

Re: [PATCH v3 2/3] Setup working tree in describe

In reply to Jeff King
Quoted 15 lines · Jeff King
Quoted 1 line · Sebastian Staudt

This ensures the given working tree is used for --dirty.

There's been a lot of digging and discussion on the list about what happens if we don't do this. Could we summarize it here?

Perhaps:

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 2 lines

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

I have not particularly been following this thread, but this proposed commit message does an excellent job of summarizing and explaining the issue and making the fix obvious (so, now I don't have to go back and read the entire thread).

Quoted 10 lines
Quoted 2 lines

The implementation of --broken uses diff-index which calls setup_work_tree() itself.

If I hadn't just read the rest of the thread, I'd probably wonder why we are talking about --broken at all. Maybe:

The --broken option similarly needs a working tree. But because the current implementation calls an external diff-index to do the work, we don't have to bother setting up the working tree in the git-describe process.

This rewrite left me slightly in the dark since I had to infer that git-diff-index calls setup_work_tree() itself. Perhaps:

...an external diff-index to do the work, which itself calls setup_work_tree(), we don't have to bother...

But that's minor.

#5 lore raw

Re: [PATCH v3 2/3] Setup working tree in describe

Quoted 11 lines · Eric Sunshine
Quoted 10 lines
Quoted 2 lines

The implementation of --broken uses diff-index which calls setup_work_tree() itself.

If I hadn't just read the rest of the thread, I'd probably wonder why we are talking about --broken at all. Maybe:

The --broken option similarly needs a working tree. But because the current implementation calls an external diff-index to do the work, we don't have to bother setting up the working tree in the git-describe process.

Quoted 7 lines

This rewrite left me slightly in the dark since I had to infer that git-diff-index calls setup_work_tree() itself. Perhaps:

...an external diff-index to do the work, which itself calls setup_work_tree(), we don't have to bother...

But that's minor.

Yeah, my reasoning was that we handed off to diff-index, so if it doesn't work, then it has its own bug. ;) But I agree it is probably better to just be explicit.

-Peff

#13 lore raw
In reply to Junio C Hamano

Am Di., 29. Jan. 2019 um 18:47 Uhr schrieb Junio C Hamano <[email protected]>:

Quoted 11 lines
Quoted 8 lines · Jeff King

The usual style is to put the whole snippet into single-quotes, and then double-quote as appropriate within it. Like:

  test_expect_failure 'describe --dirty with --work-tree' '
      (
              cd "$TEST_DIRECTORY" &&
              git --git-dir "$TRASH_DIRECTORY/.git" ...etc
Quoted 4 lines
Quoted 2 lines

Those variables will be expanded when test_expect_failure eval's the snippet.

Good.

Ok, thanks. I’ll change this in the next reroll.

Quoted 9 lines
Quoted 4 lines
Quoted 2 lines

+ grep 'A-\d\+-g[0-9a-f]\+' '$TRASH_DIRECTORY/out'

Using "\d" isn't portable.

True, but not just \d. I think using \ before special characters to force an otherwise basic regular expression to be ERE (i.e. \+ at the end) is a GNUism.

I guess I’ll use the even broader but apparently more portable A-*[0-9a-f] then. It’s used in the other checks, so this should be OK?

Quoted 10 lines
Quoted 8 lines

This regex is pretty broad. What are we checking here? If I understand the previous discussion, we just care that it doesn't have "dirty" in it, right? I don't think this regex does that, because it doesn't anchor the end of string.

If that's indeed what we're checking, then an easier check is perhaps:

! grep dirty ...

Good.

This was copied and pasted from the existing check for describe with a clean working tree. So this should be changed, too.

#10 lore raw

Re: [PATCH v3 3/3] Add test for describe with a bare repository

In reply to Jeff King

Am Di., 29. Jan. 2019 um 14:12 Uhr schrieb Jeff King <[email protected]>:

Quoted 9 lines · Sebastian Staudt
Quoted 4 lines

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

Makes sense.

Quoted 8 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
+"

What the test is doing seems sane, but the same quoting comments from the earlier patch apply.

Ok, thanks.

Quoted 1 line

-Peff

#6 lore raw

Re: [PATCH v3 2/3] Setup working tree in describe

In reply to Jeff King

Am Di., 29. Jan. 2019 um 23:35 Uhr schrieb Jeff King <[email protected]>:

Quoted 17 lines · Eric Sunshine
Quoted 15 lines
Quoted 11 lines
Quoted 3 lines

The implementation of --broken uses diff-index which calls setup_work_tree() itself.

If I hadn't just read the rest of the thread, I'd probably wonder why we are talking about --broken at all. Maybe:

The --broken option similarly needs a working tree. But because the current implementation calls an external diff-index to do the work, we don't have to bother setting up the working tree in the git-describe process.

This rewrite left me slightly in the dark since I had to infer that git-diff-index calls setup_work_tree() itself. Perhaps:

Quoted 8 lines
Quoted 4 lines

...an external diff-index to do the work, which itself calls setup_work_tree(), we don't have to bother...

But that's minor.

Yeah, my reasoning was that we handed off to diff-index, so if it doesn't work, then it has its own bug. ;) But I agree it is probably better to just be explicit.

Thanks for that valuable feedback.
Is there some trailer like "Co-authored-commit-message-by:"? ;)

Quoted 2 lines

-Peff

#14 lore raw
In reply to Sebastian Staudt
Quoted 11 lines · Sebastian Staudt
Quoted 8 lines
Quoted 3 lines
Quoted 1 line

+ grep 'A-\d\+-g[0-9a-f]\+' '$TRASH_DIRECTORY/out'

Using "\d" isn't portable.

True, but not just \d. I think using \ before special characters to force an otherwise basic regular expression to be ERE (i.e. \+ at the end) is a GNUism.

I guess I’ll use the even broader but apparently more portable A-*[0-9a-f] then. It’s used in the other checks, so this should be OK?

Yeah, that is OK, as long as you use it with case like check_describe does. Because it's a glob and not a regex, you do not have to worry about the anchoring issue.

Or if you mean to do an anchored but more general regex like:

^A-.*[0-9a-f]$

that is OK, too.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

If that's indeed what we're checking, then an easier check is perhaps:

! grep dirty ...

Good.

This was copied and pasted from the existing check for describe with a clean working tree. So this should be changed, too.

I do think that makes what we're checking more obvious, so I wouldn't mind seeing the other tests converted to use this. But it may be hard if they are relying on check_describe().

I'm OK with anything that works and is robust. :)

-Peff

#7 lore raw

Re: [PATCH v3 2/3] Setup working tree in describe

In reply to Sebastian Staudt
Quoted 6 lines · Sebastian Staudt
Quoted 3 lines

Yeah, my reasoning was that we handed off to diff-index, so if it doesn't work, then it has its own bug. ;) But I agree it is probably better to just be explicit.

Thanks for that valuable feedback.
Is there some trailer like "Co-authored-commit-message-by:"? ;)

We often say "Helped-by", but I am OK with or without that in this case. To me, making suggestions like this is all just part of review. :)

-Peff