threads / patch / 32913

patch, 3 partscontrib/subtree/t: Added tests for .gitsubtree support

Subject: [PATCH 2/3] contrib/subtree/t: Added tests for .gitsubtree support

## tl;dr

6 messages between Feb 15, 2013 and Feb 18, 2013. Diffs are folded; open one to read it.

replies: 5people: 2as markdown or json

Paul Campbell· Feb 15, 2013, 22:50 UTC · lore
add: ensure details are added to .gitsubtree
push: check for a SHA1 update line
pull: add a file on one subtree, push it to a branch, then pull into
    another subtree containing the same branch and confirm the files match
add: ensure stale .gitsubtree entry is replaced
Signed-off-by: Paul Campbell <pcampbell@kemitix.net>
---
 contrib/subtree/t/t7900-subtree.sh | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
Show changes to contrib/subtree/t/t7900-subtree.sh +30 −0
diff --git a/contrib/subtree/t/t7900-subtree.sh
b/contrib/subtree/t/t7900-subtree.sh
index 80d3399..4437dc6 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -465,4 +465,34 @@ test_expect_success 'verify one file change per commit' '
         ))
 '

+# return to mainline
+cd ../..
+
+# .gitsubtree
+test_expect_success 'added repository appears in .gitsubtree' '
+        git subtree add --prefix=copy0 sub1 &&
+        grep "^copy0 \. sub1$" .gitsubtree
+'
+
+test_expect_success 'change in subtree is pushed okay' '
+        cd copy0 && create new_file && git commit -m"Added new_file" &&
+        cd .. && git subtree push --prefix=copy0 2>&1 | \
+                grep
"^\s\{3\}[0-9a-f]\{7\}\.\.[0-9a-f]\{7\}\s\s[0-9a-f]\{40\}\s->\ssub1$"
+'
+
+test_expect_success 'pull into subtree okay' '
+        git subtree add --prefix=copy1 sub1 &&
+        git subtree add --prefix=copy2 sub1 &&
+        cd copy1 && create new_file_in_copy1 && git commit -m"Added
new_file_in_copy1" &&
+        cd .. && git subtree push --prefix=copy1 &&
+        git subtree pull --prefix=copy2 | grep "^ create mode 100644
copy2/new_file_in_copy1$"
+'
+
+test_expect_success 'replace outdated entry in .gitsubtree' '
+        echo "copy3 . sub2" >> .gitsubtree &&
+        git subtree add --prefix=copy3 sub1 &&
+        (grep "^copy3 . sub2$" .gitsubtree && die || true) &&
+        grep "^copy3 . sub1$" .gitsubtree
+'
+
 test_done
-- 
1.8.1.3.605.g02339dd
Jonathan Nieder· Feb 15, 2013, 22:56 UTC · re: Paul Campbell · lore

Re: [PATCH 2/3] contrib/subtree/t: Added tests for .gitsubtree support

Hi Paul,
Paul Campbell wrote:
> --- a/contrib/subtree/t/t7900-subtree.sh
> +++ b/contrib/subtree/t/t7900-subtree.sh
> @@ -465,4 +465,34 @@ test_expect_success 'verify one file change per commit' '
[...]
> +test_expect_success 'change in subtree is pushed okay' '
> +        cd copy0 && create new_file && git commit -m"Added new_file" &&
> +        cd .. && git subtree push --prefix=copy0 2>&1 | \

If it possible to restrict the chdirs to subshells, that can make the test more resiliant to early failures without breaking later tests.

That is:
	(
		cd copy0 &&
		create new_file &&
		test_tick &&
		git commit -m "add new_file"
	) &&
	git subtree push --prefix=copy0 >output 2>&1 &&
	grep "..." output
> +                grep "^\s\{3\}[0-9a-f]\{7\}\.\.[0-9a-f]\{7\}\s\s[0-9a-f]\{40\}\s->\ssub1$"

This might not be portable if I understand Documentation/CodingGuidelines correctly.

[...]
> +        (grep "^copy3 . sub2$" .gitsubtree && die || true) &&
	! grep "^copy3 . sub2\$" .gitsubtree &&

Hope that helps, Jonathan

Paul Campbell· Feb 15, 2013, 23:16 UTC · re: Jonathan Nieder · lore

Re: [PATCH 2/3] contrib/subtree/t: Added tests for .gitsubtree support

Hi Jonathan,
On Fri, Feb 15, 2013 at 10:56 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:
Show 26 quoted lines
> Hi Paul,
>
> Paul Campbell wrote:
>
>> --- a/contrib/subtree/t/t7900-subtree.sh
>> +++ b/contrib/subtree/t/t7900-subtree.sh
>> @@ -465,4 +465,34 @@ test_expect_success 'verify one file change per commit' '
> [...]
>> +test_expect_success 'change in subtree is pushed okay' '
>> +        cd copy0 && create new_file && git commit -m"Added new_file" &&
>> +        cd .. && git subtree push --prefix=copy0 2>&1 | \
>
> If it possible to restrict the chdirs to subshells, that can make the
> test more resiliant to early failures without breaking later tests.
>
> That is:
>
>         (
>                 cd copy0 &&
>                 create new_file &&
>                 test_tick &&
>                 git commit -m "add new_file"
>         ) &&
>         git subtree push --prefix=copy0 >output 2>&1 &&
>         grep "..." output
>
Adding them in.
Show 5 quoted lines
>> +                grep "^\s\{3\}[0-9a-f]\{7\}\.\.[0-9a-f]\{7\}\s\s[0-9a-f]\{40\}\s->\ssub1$"
>
> This might not be portable if I understand
> Documentation/CodingGuidelines correctly.
>

And it's ugly. But I believe it fits the "don't use grep -E" condition. Unless I missed something else.

Is there was a better way to verify that the push operation succeeds then grepping for a SHA1?

Show 7 quoted lines
> [...]
>> +        (grep "^copy3 . sub2$" .gitsubtree && die || true) &&
>
>         ! grep "^copy3 . sub2\$" .gitsubtree &&
>
> Hope that helps,
> Jonathan
Thanks. That's a much neater way to do it.
-- 
Paul [W] Campbell
Jonathan Nieder· Feb 17, 2013, 11:37 UTC · re: Paul Campbell · lore

Re: [PATCH 2/3] contrib/subtree/t: Added tests for .gitsubtree support

Paul Campbell wrote:
> Is there was a better way to verify that the push operation succeeds
> then grepping for a SHA1?

IIRC then when a push fails, it will exit with nonzero status (so the usual &&-chaining would propagate the error).

Alternatively, one can fetch, ls-remote, or enter the target repo and use history inspection tools to check that the result is as expected.

Hope that helps, Jonathan

Paul Campbell· Feb 17, 2013, 15:26 UTC · re: Jonathan Nieder · lore

Re: [PATCH 2/3] contrib/subtree/t: Added tests for .gitsubtree support

On Sun, Feb 17, 2013 at 11:37 AM, Jonathan Nieder <jrnieder@gmail.com> wrote:
Show 13 quoted lines
> Paul Campbell wrote:
>
>> Is there was a better way to verify that the push operation succeeds
>> then grepping for a SHA1?
>
> IIRC then when a push fails, it will exit with nonzero status (so the
> usual &&-chaining would propagate the error).
>
> Alternatively, one can fetch, ls-remote, or enter the target repo and
> use history inspection tools to check that the result is as expected.
>
> Hope that helps,
> Jonathan
Thanks Jonathan.
Here's the updated version of the tests:
 contrib/subtree/t/t7900-subtree.sh | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
Show changes to contrib/subtree/t/t7900-subtree.sh +33 −0
diff --git a/contrib/subtree/t/t7900-subtree.sh
b/contrib/subtree/t/t7900-subtree.sh
index 80d3399..e7bb911 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -465,4 +465,37 @@ test_expect_success 'verify one file change per commit' '
         ))
 '

+# return to mainline
+cd ../..
+
+# .gitsubtree
+test_expect_success 'added repository appears in .gitsubtree' '
+	git subtree add --prefix=copy0 sub1 &&
+	grep "^copy0 \. sub1$" .gitsubtree
+'
+
+test_expect_success 'change in subtree is pushed okay' '
+	(cd copy0 && create new_file && git commit -m"Added new_file") &&
+	git ls-tree refs/heads/sub1 >output &&
+	! grep "new_file$" output &&
+	git subtree push --prefix=copy0 &&
+	git ls-tree refs/heads/sub1 >output &&
+	grep "new_file$" output
+'
+
+test_expect_success 'pull into subtree okay' '
+	git subtree add --prefix=copy1 sub1 &&
+	git subtree add --prefix=copy2 sub1 &&
+	(cd copy1 && create new_file_in_copy1 && git commit -m"Added
new_file_in_copy1") &&
+	git subtree push --prefix=copy1 &&
+	git subtree pull --prefix=copy2 | grep "^ create mode 100644
copy2/new_file_in_copy1$"
+'
+
+test_expect_success 'replace outdated entry in .gitsubtree' '
+	echo "copy3 . sub2" >>.gitsubtree &&
+	git subtree add --prefix=copy3 sub1 &&
+	! grep "^copy3 . sub2$" .gitsubtree &&
+	grep "^copy3 . sub1$" .gitsubtree
+'
+
 test_done
-- 
1.8.1.3.605.g02339dd


-- 
Paul [W] Campbell
Jonathan Nieder· Feb 18, 2013, 00:35 UTC · re: Paul Campbell · lore

Re: [PATCH 2/3] contrib/subtree/t: Added tests for .gitsubtree support

Paul Campbell wrote:
> Here's the updated version of the tests:
Just a few more nits:
> --- a/contrib/subtree/t/t7900-subtree.sh
> +++ b/contrib/subtree/t/t7900-subtree.sh
> @@ -465,4 +465,37 @@ test_expect_success 'verify one file change per commit' '
[...]
> +test_expect_success 'change in subtree is pushed okay' '
> +	(cd copy0 && create new_file && git commit -m"Added new_file") &&
Style: this would be easier to read with each command on a separate
line, like so:
	(
		cd copy0 &&
		create new_file &&
		test_tick &&
		git commit -m "Add new_file"
	) &&
[...]
> +test_expect_success 'pull into subtree okay' '
> +	git subtree add --prefix=copy1 sub1 &&
> +	git subtree add --prefix=copy2 sub1 &&
> +	(cd copy1 && create new_file_in_copy1 && git commit -m"Added new_file_in_copy1") &&

Likewise (and as a nice side-benefit, it would avoid a long line that mailers like to wrap).

> +	git subtree push --prefix=copy1 &&
> +	git subtree pull --prefix=copy2 | grep "^ create mode 100644 copy2/new_file_in_copy1$"

Likewise. More importantly, this forgets the exit status from "git subtree pull", so if it were to segfault after writing appropriate output, the test wouldn't notice. How about:

	git subtree pull --prefix=copy2 >output &&
	grep "^ create mode 100644 copy2/new_file_in_copy1\$" output

Thanks, Jonathan

← back to recent threads