Re: [PATCH 11/13] contrib/subtree: Make each test self-contained

2013-02-18 Thread greened
Junio C Hamano  writes:

> I also think it would be a good idea for you to learn to push back
> to the original authors; fixing problems in patches by others, while
> is a good way to learn how their thinking process went, is not
> necessarily fun.

Sure, but in this case I said I'd handle it so I will.

  -David
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 11/13] contrib/subtree: Make each test self-contained

2013-02-05 Thread Junio C Hamano
gree...@obbligato.org writes:

> Junio C Hamano  writes:
>
>> "David A. Greene"  writes:
>>
>>> +test_create_commit() (
>>> +   repo=$1
>>> +   commit=$2
>>> +   cd "$repo"
>>> +   mkdir -p "$(dirname "$commit")"
>>> +   echo "$commit" > "$commit"
>>
>> Style.
>
> I need a little more explanation.  :)  Is there a style guide somewhere?

Documentation/CodingGuidelines?

>
>>> +   git add "$commit"
>>> +   git commit -m "$commit"
>>> +)
>>
>> Very nice, but don't we want to check for possible errors in any of
>> the above commands?
>
> I'll fix that.  :)
> ...
> Ok.  I'll rework this.

Thanks.

I also think it would be a good idea for you to learn to push back
to the original authors; fixing problems in patches by others, while
is a good way to learn how their thinking process went, is not
necessarily fun.

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 11/13] contrib/subtree: Make each test self-contained

2013-02-05 Thread David A. Greene
From: Techlive Zheng 

Signed-off-by: Techlive Zheng 
Signed-off-by: David A. Greene 
---
 contrib/subtree/t/t7900-subtree.sh |  871 +---
 1 file changed, 613 insertions(+), 258 deletions(-)

diff --git a/contrib/subtree/t/t7900-subtree.sh 
b/contrib/subtree/t/t7900-subtree.sh
index 9cfaaf9..769b116 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -12,12 +12,6 @@ export TEST_DIRECTORY=$(pwd)/../../../t
 
 . ../../../t/test-lib.sh
 
-create()
-{
-   echo "$1" >"$1"
-   git add "$1"
-}
-
 fixnl()
 {
t=""
@@ -37,11 +31,6 @@ multiline()
done
 }
 
-undo()
-{
-   git reset --hard HEAD~
-}
-
 test_equal()
 {
test_debug 'echo'
@@ -78,381 +67,746 @@ join_commits()
echo "$commit $all"
 }
 
+test_create_commit() (
+   repo=$1
+   commit=$2
+   cd "$repo"
+   mkdir -p "$(dirname "$commit")"
+   echo "$commit" > "$commit"
+   git add "$commit"
+   git commit -m "$commit"
+)
+
 last_commit_message()
 {
git log --pretty=format:%s -1
 }
 
-test_expect_success 'init subproj' '
-   test_create_repo subproj
-'
-
-# To the subproject!
-cd subproj
-
-test_expect_success 'add sub1' '
-   create sub1 &&
-   git commit -m "sub1" &&
-   git branch sub1 &&
-   git branch -m master subproj
-'
-
-# Save this hash for testing later.
-
-subdir_hash=`git rev-parse HEAD`
-
-test_expect_success 'add sub2' '
-   create sub2 &&
-   git commit -m "sub2" &&
-   git branch sub2
-'
-
-test_expect_success 'add sub3' '
-   create sub3 &&
-   git commit -m "sub3" &&
-   git branch sub3
-'
-
-# Back to mainline
-cd ..
-
-test_expect_success 'add main4' '
-   create main4 &&
-   git commit -m "main4" &&
-   git branch -m master mainline &&
-   git branch init
-'
+#
+# Tests for 'git subtree add'
+#
 
-test_expect_success 'fetch subproj history' '
-   git fetch ./subproj sub1 &&
-   git branch sub1 FETCH_HEAD
-'
 
 test_expect_success 'no pull from non-existant subtree' '
-   test_must_fail git subtree pull --prefix=subdir ./subproj sub1
+   test_create_repo "$test_count" &&
+   test_create_repo "$test_count/subproj" &&
+   test_create_commit "$test_count" main1 &&
+   test_create_commit "$test_count/subproj" sub1 &&
+   (
+   cd "$test_count" &&
+   git fetch ./subproj master &&
+   test_must_fail git subtree pull --prefix=subdir ./subproj master
+   )
 '
 
 test_expect_success 'no merge from non-existant subtree' '
+   test_create_repo "$test_count" &&
+   test_create_repo "$test_count/subproj" &&
+   test_create_commit "$test_count" main1 &&
+   test_create_commit "$test_count/subproj" sub1 &&
+   (
+   cd "$test_count" &&
+   git fetch ./subproj master &&
test_must_fail git subtree merge --prefix=subdir FETCH_HEAD
+   )
 '
 
 test_expect_success 'add subproj as subtree into subdir/ with --prefix' '
+   test_create_repo "$test_count" &&
+   test_create_repo "$test_count/subproj" &&
+   test_create_commit "$test_count" main1 &&
+   test_create_commit "$test_count/subproj" sub1 &&
+   (
+   cd "$test_count" &&
+   git fetch ./subproj master &&
git subtree add --prefix=subdir FETCH_HEAD &&
-   test_equal "$(last_commit_message)" "Add '\''subdir/'\'' from 
commit '\''$(git rev-parse FETCH_HEAD)'\''" &&
-   undo
+   test_equal "$(last_commit_message)" "Add '\''subdir/'\'' from 
commit '\''$(git rev-parse FETCH_HEAD)'\''"
+   )
 '
 
 test_expect_success 'add subproj as subtree into subdir/ with --prefix and 
--message' '
+   test_create_repo "$test_count" &&
+   test_create_repo "$test_count/subproj" &&
+   test_create_commit "$test_count" main1 &&
+   test_create_commit "$test_count/subproj" sub1 &&
+   (
+   cd "$test_count" &&
+   git fetch ./subproj master &&
git subtree add --prefix=subdir --message="Added subproject" 
FETCH_HEAD &&
-   test_equal "$(last_commit_message)" "Added subproject" &&
-   undo
+   test_equal "$(last_commit_message)" "Added subproject"
+   )
 '
 
 test_expect_success 'add subproj as subtree into subdir/ with --prefix as -P 
and --message as -m' '
+   test_create_repo "$test_count" &&
+   test_create_repo "$test_count/subproj" &&
+   test_create_commit "$test_count" main1 &&
+   test_create_commit "$test_count/subproj" sub1 &&
+   (
+   cd "$test_count" &&
+   git fetch ./subproj master &&
git subtree add -P subdir -m "Added subproject" FETCH_HEAD &&
-   test_equal "$(last

Re: [PATCH 11/13] contrib/subtree: Make each test self-contained

2013-02-04 Thread Junio C Hamano
"David A. Greene"  writes:

> +test_create_commit() (
> + repo=$1
> + commit=$2
> + cd "$repo"
> + mkdir -p "$(dirname "$commit")"
> + echo "$commit" > "$commit"

Style.

> + git add "$commit"
> + git commit -m "$commit"
> +)

Very nice, but don't we want to check for possible errors in any of
the above commands?

>  last_commit_message()
>  {
>   git log --pretty=format:%s -1
>  }
>  
> +#
> +# Tests for 'git subtree add'
> +#
>  
> -test_expect_success 'fetch subproj history' '
> - git fetch ./subproj sub1 &&
> - git branch sub1 FETCH_HEAD
> -'
>  
>  test_expect_success 'no pull from non-existant subtree' '
> - test_must_fail git subtree pull --prefix=subdir ./subproj sub1
> + test_create_repo "$test_count" &&
> + test_create_repo "$test_count/subproj" &&
> + test_create_commit "$test_count" main1 &&
> + test_create_commit "$test_count/subproj" sub1 &&
> + (
> + cd "$test_count" &&
> + git fetch ./subproj master &&
> + test_must_fail git subtree pull --prefix=subdir ./subproj master
> + )
>  '

The goal of making each tests indenendent is a very good one, but
we'd really prefer not to see $test_count which is an implementation
detail of the test framework to be used like this.  It will make it
unnecessarily harder to improve the test framework (e.g. it may want
to stop using the $test_count variable).

This is not limited to this variable, but all other $test_anything
variable.  Earlier I wanted to update the definition of test_tick
which happens to be decimal number of seconds since epoch, but some
tests were comparing it with the raw values read from cat-file output
for a commit object, and it was really painful.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 11/13] contrib/subtree: Make each test self-contained

2013-02-04 Thread David A. Greene
From: Techlive Zheng 

Signed-off-by: Techlive Zheng 
Signed-off-by: David A. Greene 
---
 contrib/subtree/t/t7900-subtree.sh |  871 +---
 1 file changed, 613 insertions(+), 258 deletions(-)

diff --git a/contrib/subtree/t/t7900-subtree.sh 
b/contrib/subtree/t/t7900-subtree.sh
index 9cfaaf9..769b116 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -12,12 +12,6 @@ export TEST_DIRECTORY=$(pwd)/../../../t
 
 . ../../../t/test-lib.sh
 
-create()
-{
-   echo "$1" >"$1"
-   git add "$1"
-}
-
 fixnl()
 {
t=""
@@ -37,11 +31,6 @@ multiline()
done
 }
 
-undo()
-{
-   git reset --hard HEAD~
-}
-
 test_equal()
 {
test_debug 'echo'
@@ -78,381 +67,746 @@ join_commits()
echo "$commit $all"
 }
 
+test_create_commit() (
+   repo=$1
+   commit=$2
+   cd "$repo"
+   mkdir -p "$(dirname "$commit")"
+   echo "$commit" > "$commit"
+   git add "$commit"
+   git commit -m "$commit"
+)
+
 last_commit_message()
 {
git log --pretty=format:%s -1
 }
 
-test_expect_success 'init subproj' '
-   test_create_repo subproj
-'
-
-# To the subproject!
-cd subproj
-
-test_expect_success 'add sub1' '
-   create sub1 &&
-   git commit -m "sub1" &&
-   git branch sub1 &&
-   git branch -m master subproj
-'
-
-# Save this hash for testing later.
-
-subdir_hash=`git rev-parse HEAD`
-
-test_expect_success 'add sub2' '
-   create sub2 &&
-   git commit -m "sub2" &&
-   git branch sub2
-'
-
-test_expect_success 'add sub3' '
-   create sub3 &&
-   git commit -m "sub3" &&
-   git branch sub3
-'
-
-# Back to mainline
-cd ..
-
-test_expect_success 'add main4' '
-   create main4 &&
-   git commit -m "main4" &&
-   git branch -m master mainline &&
-   git branch init
-'
+#
+# Tests for 'git subtree add'
+#
 
-test_expect_success 'fetch subproj history' '
-   git fetch ./subproj sub1 &&
-   git branch sub1 FETCH_HEAD
-'
 
 test_expect_success 'no pull from non-existant subtree' '
-   test_must_fail git subtree pull --prefix=subdir ./subproj sub1
+   test_create_repo "$test_count" &&
+   test_create_repo "$test_count/subproj" &&
+   test_create_commit "$test_count" main1 &&
+   test_create_commit "$test_count/subproj" sub1 &&
+   (
+   cd "$test_count" &&
+   git fetch ./subproj master &&
+   test_must_fail git subtree pull --prefix=subdir ./subproj master
+   )
 '
 
 test_expect_success 'no merge from non-existant subtree' '
+   test_create_repo "$test_count" &&
+   test_create_repo "$test_count/subproj" &&
+   test_create_commit "$test_count" main1 &&
+   test_create_commit "$test_count/subproj" sub1 &&
+   (
+   cd "$test_count" &&
+   git fetch ./subproj master &&
test_must_fail git subtree merge --prefix=subdir FETCH_HEAD
+   )
 '
 
 test_expect_success 'add subproj as subtree into subdir/ with --prefix' '
+   test_create_repo "$test_count" &&
+   test_create_repo "$test_count/subproj" &&
+   test_create_commit "$test_count" main1 &&
+   test_create_commit "$test_count/subproj" sub1 &&
+   (
+   cd "$test_count" &&
+   git fetch ./subproj master &&
git subtree add --prefix=subdir FETCH_HEAD &&
-   test_equal "$(last_commit_message)" "Add '\''subdir/'\'' from 
commit '\''$(git rev-parse FETCH_HEAD)'\''" &&
-   undo
+   test_equal "$(last_commit_message)" "Add '\''subdir/'\'' from 
commit '\''$(git rev-parse FETCH_HEAD)'\''"
+   )
 '
 
 test_expect_success 'add subproj as subtree into subdir/ with --prefix and 
--message' '
+   test_create_repo "$test_count" &&
+   test_create_repo "$test_count/subproj" &&
+   test_create_commit "$test_count" main1 &&
+   test_create_commit "$test_count/subproj" sub1 &&
+   (
+   cd "$test_count" &&
+   git fetch ./subproj master &&
git subtree add --prefix=subdir --message="Added subproject" 
FETCH_HEAD &&
-   test_equal "$(last_commit_message)" "Added subproject" &&
-   undo
+   test_equal "$(last_commit_message)" "Added subproject"
+   )
 '
 
 test_expect_success 'add subproj as subtree into subdir/ with --prefix as -P 
and --message as -m' '
+   test_create_repo "$test_count" &&
+   test_create_repo "$test_count/subproj" &&
+   test_create_commit "$test_count" main1 &&
+   test_create_commit "$test_count/subproj" sub1 &&
+   (
+   cd "$test_count" &&
+   git fetch ./subproj master &&
git subtree add -P subdir -m "Added subproject" FETCH_HEAD &&
-   test_equal "$(last