[PATCH 03/10] t0002: abstract away SHA-1-specific constants

2018-06-04 Thread brian m. carlson
Adjust the test so that it computes variables for object IDs instead of
using hard-coded hashes.

Signed-off-by: brian m. carlson 
---
 t/t0002-gitfile.sh | 26 ++
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/t/t0002-gitfile.sh b/t/t0002-gitfile.sh
index 3691023d51..020af4c53c 100755
--- a/t/t0002-gitfile.sh
+++ b/t/t0002-gitfile.sh
@@ -89,14 +89,16 @@ test_expect_success 'enter_repo non-strict mode' '
cd enter_repo &&
test_tick &&
test_commit foo &&
+   git rev-parse HEAD >head-revision &&
mv .git .realgit &&
echo "gitdir: .realgit" >.git
) &&
+   head=$(cat enter_repo/head-revision) &&
git ls-remote enter_repo >actual &&
-   cat >expected <<-\EOF &&
-   946e985ab20de757ca5b872b16d64e92ff3803a9HEAD
-   946e985ab20de757ca5b872b16d64e92ff3803a9refs/heads/master
-   946e985ab20de757ca5b872b16d64e92ff3803a9refs/tags/foo
+   cat >expected <<-EOF &&
+   $head   HEAD
+   $head   refs/heads/master
+   $head   refs/tags/foo
EOF
test_cmp expected actual
 '
@@ -107,20 +109,20 @@ test_expect_success 'enter_repo linked checkout' '
git worktree add  ../foo refs/tags/foo
) &&
git ls-remote foo >actual &&
-   cat >expected <<-\EOF &&
-   946e985ab20de757ca5b872b16d64e92ff3803a9HEAD
-   946e985ab20de757ca5b872b16d64e92ff3803a9refs/heads/master
-   946e985ab20de757ca5b872b16d64e92ff3803a9refs/tags/foo
+   cat >expected <<-EOF &&
+   $head   HEAD
+   $head   refs/heads/master
+   $head   refs/tags/foo
EOF
test_cmp expected actual
 '
 
 test_expect_success 'enter_repo strict mode' '
git ls-remote --upload-pack="git upload-pack --strict" foo/.git >actual 
&&
-   cat >expected <<-\EOF &&
-   946e985ab20de757ca5b872b16d64e92ff3803a9HEAD
-   946e985ab20de757ca5b872b16d64e92ff3803a9refs/heads/master
-   946e985ab20de757ca5b872b16d64e92ff3803a9refs/tags/foo
+   cat >expected <<-EOF &&
+   $head   HEAD
+   $head   refs/heads/master
+   $head   refs/tags/foo
EOF
test_cmp expected actual
 '


Re: [PATCH 03/10] t0002: abstract away SHA-1-specific constants

2018-06-11 Thread Eric Sunshine
On Mon, Jun 4, 2018 at 7:52 PM, brian m. carlson
 wrote:
> Adjust the test so that it computes variables for object IDs instead of
> using hard-coded hashes.
>
> Signed-off-by: brian m. carlson 
> ---
> diff --git a/t/t0002-gitfile.sh b/t/t0002-gitfile.sh
> @@ -89,14 +89,16 @@ test_expect_success 'enter_repo non-strict mode' '
> cd enter_repo &&
> test_tick &&
> test_commit foo &&
> +   git rev-parse HEAD >head-revision &&
> mv .git .realgit &&
> echo "gitdir: .realgit" >.git
> ) &&
> +   head=$(cat enter_repo/head-revision) &&

Stashing the value temporarily in a file ("head-revision") is
unnecessary and somewhat ugly. Just grab it directly after the
subshell exits:

(
cd enter_repo &&
...
) &&
head=$(git -C enter_repo rev-parse HEAD) &&
...