Skip to contentSkip to conversation

HOME must be set before calling git-init when creating test repositories

PATCH In review Alex Riesen 3 participants 14 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 HOME must be set before calling git-init when creating test repositories

Otherwise the created test repositories will be affected by users ~/.gitconfig. For example, setting core.logAllrefupdates in users config will make all calls to "git config --unset core.logAllrefupdates" fail which will break the first test which uses the statement and expects it to succeed.

---

The first test which fails is t2017, btw.
I still wonder if this should be moved even further up.

 t/test-lib.sh |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
t/test-lib.sh +3 -3
index 7cc9a52..4f394c3 100644
@@ -984,14 +984,14 @@ rm -fr "$test" || {
 	exit 1
 }
 
+HOME=$(pwd)
+export HOME
+
 test_create_repo "$test"
 # Use -P to resolve symlinks in our working directory so that the cwd
 # in subprocesses like git equals our $PWD (for pathname comparisons).
 cd -P "$test" || exit 1
 
-HOME=$(pwd)
-export HOME
-
 this_test=${0##*/}
 this_test=${this_test%%-*}
 for skp in $GIT_SKIP_TESTS
Signature · 1 line
1.7.4.1.271.g4540f
#1 lore raw

PATCH 1/1 HOME must be set before calling git-init when creating test repositories

Otherwise the created test repositories will be affected by users ~/.gitconfig. For example, setting core.logAllrefupdates in users config will make all calls to "git config --unset core.logAllrefupdates" fail which will break the first test which uses the statement and expects it to succeed.

---

Aah... Sorry. Missed the test's part of the new HOME.

 t/test-lib.sh |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
t/test-lib.sh +3 -3
index 7cc9a52..8792e4a 100644
@@ -984,14 +984,14 @@ rm -fr "$test" || {
 	exit 1
 }
 
+HOME=$(pwd)/"$test"
+export HOME
+
 test_create_repo "$test"
 # Use -P to resolve symlinks in our working directory so that the cwd
 # in subprocesses like git equals our $PWD (for pathname comparisons).
 cd -P "$test" || exit 1
 
-HOME=$(pwd)
-export HOME
-
 this_test=${0##*/}
 this_test=${this_test%%-*}
 for skp in $GIT_SKIP_TESTS
Signature · 1 line
1.7.4.1.271.g4540f
#2 lore raw
In reply to Alex Riesen
Quoted 4 lines · Alex Riesen

Otherwise the created test repositories will be affected by users ~/.gitconfig. For example, setting core.logAllrefupdates in users config will make all calls to "git config --unset core.logAllrefupdates" fail which will break the first test which uses the statement and expects it to succeed.

Doesn't this change the location of HOME used during the test as well?

#3 lore raw
Quoted 9 lines · Junio C Hamano
Quoted 4 lines · Alex Riesen

Otherwise the created test repositories will be affected by users ~/.gitconfig. For example, setting core.logAllrefupdates in users config will make all calls to "git config --unset core.logAllrefupdates" fail which will break the first test which uses the statement and expects it to succeed.

Doesn't this change the location of HOME used during the test as well?

As long as the test only includes test-lib.sh only once - it doesn't. Why? Or rather, how?

#4 lore raw
Quoted 6 lines · Alex Riesen
Quoted 1 line · Junio C Hamano

Doesn't this change the location of HOME used during the test as well?

As long as the test only includes test-lib.sh only once - it doesn't. Why? Or rather, how?

I thought you moved HOME=$(pwd) across "cd somewhere-else". Doesn't it change what is returned from pwd?

#5 lore raw
Quoted 4 lines · Junio C Hamano
Quoted 2 lines · Alex Riesen

On Fri, Mar 25, 2011 at 21:49, Junio C Hamano <[email protected]> wrote:

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Doesn't this change the location of HOME used during the test as well?

As long as the test only includes test-lib.sh only once - it doesn't. Why? Or rather, how?

I thought you moved HOME=$(pwd) across "cd somewhere-else".  Doesn't it change what is returned from pwd?

Oh, it does. That's why the second patch (prefixed "[PATCH, fixed]"). It makes HOME to be "$(pwd)/somewhere-else", or precisely:

  HOME="$(pwd)"/"$test"
  export HOME
#6 lore raw
Quoted 14 lines · Alex Riesen
Quoted 4 lines · Junio C Hamano
Quoted 2 lines · Alex Riesen

On Fri, Mar 25, 2011 at 21:49, Junio C Hamano <[email protected]> wrote:

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Doesn't this change the location of HOME used during the test as well?

As long as the test only includes test-lib.sh only once - it doesn't. Why? Or rather, how?

I thought you moved HOME=$(pwd) across "cd somewhere-else".  Doesn't it change what is returned from pwd?

Quoted 5 lines

Oh, it does. That's why the second patch (prefixed "[PATCH, fixed]"). It makes HOME to be "$(pwd)/somewhere-else", or precisely:

  HOME="$(pwd)"/"$test"
  export HOME

What happens to people who has non-empty "$root", iow, their $test begins with '/'?

I am not saying that having HOME at t/ directory instead of t/trash-*/ directory would necessarily break things (I don't know). I am just pointing out that the patch changes behaviour.

#7 lore raw
Quoted 16 lines · Junio C Hamano
Quoted 14 lines · Alex Riesen
Quoted 12 lines · Junio C Hamano
Quoted 6 lines · Alex Riesen
Quoted 1 line · Junio C Hamano

Doesn't this change the location of HOME used during the test as well?

As long as the test only includes test-lib.sh only once - it doesn't. Why? Or rather, how?

I thought you moved HOME=$(pwd) across "cd somewhere-else".  Doesn't it change what is returned from pwd?

Quoted 8 lines
Quoted 5 lines

Oh, it does. That's why the second patch (prefixed "[PATCH, fixed]"). It makes HOME to be "$(pwd)/somewhere-else", or precisely:

  HOME="$(pwd)"/"$test"
  export HOME

What happens to people who has non-empty "$root", iow, their $test begins with '/'?

It's still under $test then.

Quoted 3 lines

I am not saying that having HOME at t/ directory instead of t/trash-*/ directory would necessarily break things (I don't know).  I am just pointing out that the patch changes behaviour.

It does. I still think we're better off using the test's trash directory for a this. For instance, consider the case when a user's .gitconfig created by one of the tests collides with .gitconfig's of the other tests. Either when running in parallel or just sequentially: the .gitconfig in "t/" is not cleaned up after a test finishes.

#8 lore raw
Quoted 10 lines · Alex Riesen
Quoted 8 lines
Quoted 5 lines

Oh, it does. That's why the second patch (prefixed "[PATCH, fixed]"). It makes HOME to be "$(pwd)/somewhere-else", or precisely:

  HOME="$(pwd)"/"$test"
  export HOME

What happens to people who has non-empty "$root", iow, their $test begins with '/'?

It's still under $test then.

No, it's totally broken. $(pwd)/$test is nonsensical. The code right above your change guarantees that $test is an absolute path, either because the user gave us an absolute $root or because it has been prepended with $TEST_DIRECTORY (which itself comes from $(pwd)).

So the change you want is HOME=$test. But note that the code looks like this then:

HOME=$test
export HOME
test_create_repo "$test"
cd -P "$test"

meaning that test_create_repo sees a non-existent HOME. I don't think that matters, but if it did, you could do:

HOME=$TEST_DIRECTORY
export HOME
test_create_repo "$test"
cd -P "$test"
HOME=$test

-Peff

#9 lore raw

PATCH 1/1 HOME must be set before calling git-init when creating test repositories

Otherwise the created test repositories will be affected by users ~/.gitconfig. For example, setting core.logAllrefupdates in users config will make all calls to "git config --unset core.logAllrefupdates" fail which will break the first test which uses the statement and expects it to succeed.

---

Jeff King, Sat, Mar 26, 2011 15:11:18 +0100:

Quoted 11 lines · Alex Riesen
Quoted 10 lines
Quoted 9 lines
Quoted 6 lines

Oh, it does. That's why the second patch (prefixed "[PATCH, fixed]"). It makes HOME to be "$(pwd)/somewhere-else", or precisely:

  HOME="$(pwd)"/"$test"
  export HOME

What happens to people who has non-empty "$root", iow, their $test begins with '/'?

Quoted 6 lines
Quoted 1 line

It's still under $test then.

No, it's totally broken. $(pwd)/$test is nonsensical. The code right above your change guarantees that $test is an absolute path, either because the user gave us an absolute $root or because it has been prepended with $TEST_DIRECTORY (which itself comes from $(pwd)).

I see. I mistook "$root" for the root of a filesystem, not the variable in test-lib.sh. How about this, than?

 t/test-lib.sh |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
t/test-lib.sh +4 -3
index 7cc9a52..2b24c3d 100644
@@ -984,14 +984,15 @@ rm -fr "$test" || {
 	exit 1
 }
 
+HOME="$(pwd)/$test"
+test -n "$root" && HOME="$test"
+export HOME
+
 test_create_repo "$test"
 # Use -P to resolve symlinks in our working directory so that the cwd
 # in subprocesses like git equals our $PWD (for pathname comparisons).
 cd -P "$test" || exit 1
 
-HOME=$(pwd)
-export HOME
-
 this_test=${0##*/}
 this_test=${this_test%%-*}
 for skp in $GIT_SKIP_TESTS
Signature · 1 line
1.7.4.1.471.gab01
#10 lore raw
Quoted 7 lines · Alex Riesen
Quoted 4 lines

No, it's totally broken. $(pwd)/$test is nonsensical. The code right above your change guarantees that $test is an absolute path, either because the user gave us an absolute $root or because it has been prepended with $TEST_DIRECTORY (which itself comes from $(pwd)).

I see. I mistook "$root" for the root of a filesystem, not the variable in test-lib.sh. How about this, than?

Oops, when I said "$test" I meant to say $TRASH_DIRECTORY. That is, $TRASH_DIRECTORY is always the absolute path to the trash.

t/test-lib.sh rm -fr "$test" || { · line 989

Quoted 3 lines
t/test-lib.sh +3 -0
+HOME="$(pwd)/$test"
+test -n "$root" && HOME="$test"
+export HOME

So you can simplify this to just:

HOME=$TRASH_DIRECTORY

and not have to worry about checking $root at all.

Sorry for the confusion.

-Peff

#11 lore raw
Quoted 13 lines · Jeff King
Quoted 7 lines · Alex Riesen
Quoted 4 lines

No, it's totally broken. $(pwd)/$test is nonsensical. The code right above your change guarantees that $test is an absolute path, either because the user gave us an absolute $root or because it has been prepended with $TEST_DIRECTORY (which itself comes from $(pwd)).

I see. I mistook "$root" for the root of a filesystem, not the variable in test-lib.sh. How about this, than?

Oops, when I said "$test" I meant to say $TRASH_DIRECTORY. That is, $TRASH_DIRECTORY is always the absolute path to the trash.

Quoted 8 lines

t/test-lib.sh rm -fr "$test" || { · line 989

Quoted 3 lines
t/test-lib.sh +3 -0
+HOME="$(pwd)/$test"
+test -n "$root" && HOME="$test"
+export HOME

So you can simplify this to just:

HOME=$TRASH_DIRECTORY

Aah... I should have actually looked at the "case" which sets TRASH_DIRECTORY!

Will resend in a moment.

#12 lore raw

PATCH 1/1 HOME must be set before calling git-init when creating test repositories

Otherwise the created test repositories will be affected by users ~/.gitconfig. For example, setting core.logAllrefupdates in users config will make all calls to "git config --unset core.logAllrefupdates" fail which will break the first test which uses the statement and expects it to succeed.

---

Alex Riesen, Sat, Mar 26, 2011 19:42:14 +0100:

Quoted 10 lines · Jeff King
Quoted 4 lines

So you can simplify this to just:

HOME=$TRASH_DIRECTORY

Aah... I should have actually looked at the "case" which sets TRASH_DIRECTORY!

Will resend in a moment.

Here.

 t/test-lib.sh |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
t/test-lib.sh +3 -3
index 7cc9a52..7965b74 100644
@@ -984,14 +984,14 @@ rm -fr "$test" || {
 	exit 1
 }
 
+HOME="$TRASH_DIRECTORY"
+export HOME
+
 test_create_repo "$test"
 # Use -P to resolve symlinks in our working directory so that the cwd
 # in subprocesses like git equals our $PWD (for pathname comparisons).
 cd -P "$test" || exit 1
 
-HOME=$(pwd)
-export HOME
-
 this_test=${0##*/}
 this_test=${this_test%%-*}
 for skp in $GIT_SKIP_TESTS
Signature · 1 line
1.7.4.1.471.gab01
#13 lore raw
Quoted 9 lines · Alex Riesen
t/test-lib.sh +1 -0
index 7cc9a52..7965b74 100644
@@ -984,14 +984,14 @@ rm -fr "$test" || {
 	exit 1
 }
 
+HOME="$TRASH_DIRECTORY"

t/test-lib.sh rm -fr "$test" || { · line 994

Quoted 10 lines
t/test-lib.sh +2 -3
+export HOME
+
 test_create_repo "$test"
 # Use -P to resolve symlinks in our working directory so that the cwd
 # in subprocesses like git equals our $PWD (for pathname comparisons).
 cd -P "$test" || exit 1
 
-HOME=$(pwd)
-export HOME
-

That looks right to me. Thanks.

-Peff