# [PATCH v3] Make GIT_INDEX_FILE apply to git-commit

3 messages from 2007-11-11 to 2007-11-12. Participants: Rémi Vanicat, Junio C Hamano, Remi Vanicat.
Thread: https://gitlist.dev/t/10803

## Rémi Vanicat, 2007-11-11 12:28

Subject: [PATCH v3] Make GIT_INDEX_FILE apply to git-commit
Message-ID: <87r6ixj7af.dlv@vanicat.homelinux.org>
URL: https://gitlist.dev/e/87r6ixj7af.dlv%40vanicat.homelinux.org

```
Currently, when committing, git-commit ignore the value of
GIT_INDEX_FILE, and always use $GIT_DIR/index. This patch
fix it.

Signed-off-by: Rémi Vanicat <vanicat@debian.org>
---
 git-commit.sh     |    2 +-
 t/t7500-commit.sh |   13 +++++++++++++
 2 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/git-commit.sh b/git-commit.sh
index fcb8443..6490045 100755
--- a/git-commit.sh
+++ b/git-commit.sh
@@ -26,7 +26,7 @@ refuse_partial () {
 }
 
 TMP_INDEX=
-THIS_INDEX="$GIT_DIR/index"
+THIS_INDEX="${GIT_INDEX_FILE:-$GIT_DIR/index}"
 NEXT_INDEX="$GIT_DIR/next-index$$"
 rm -f "$NEXT_INDEX"
 save_index () {
diff --git a/t/t7500-commit.sh b/t/t7500-commit.sh
index abbf54b..3e5abef 100755
--- a/t/t7500-commit.sh
+++ b/t/t7500-commit.sh
@@ -93,4 +93,17 @@ test_expect_success 'commit message from file should override template' '
        commit_msg_is "standard input msg"
 '
 
+test_expect_success 'using GIT_INDEX_FILE' '
+
+       echo "some new content" >file &&
+       GIT_INDEX_FILE=.git/another_index git add file &&
+       GIT_INDEX_FILE=.git/another_index \
+               git commit -m "commit using another index" &&
+       git reset HEAD &&
+       git diff HEAD -- file >current &&
+       touch empty-file &&
+       diff empty-file current
+
+'
+
 test_done
-- 
1.5.3.5

```

## Junio C Hamano, 2007-11-11 19:59

Subject: Re: [PATCH v3] Make GIT_INDEX_FILE apply to git-commit
Message-ID: <7vlk94d043.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vlk94d043.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <87r6ixj7af.dlv@vanicat.homelinux.org>

```
Rémi Vanicat <vanicat@debian.org> writes:

> @@ -26,7 +26,7 @@ refuse_partial () {
>  }
>  
>  TMP_INDEX=
> -THIS_INDEX="$GIT_DIR/index"
> +THIS_INDEX="${GIT_INDEX_FILE:-$GIT_DIR/index}"
>  NEXT_INDEX="$GIT_DIR/next-index$$"
>  rm -f "$NEXT_INDEX"
>  save_index () {

This is just a "purist" question, but I wonder if we want to
differentiate the case where GIT_INDEX_FILE is set to empty and
GIT_INDEX_FILE is not set at all?

> diff --git a/t/t7500-commit.sh b/t/t7500-commit.sh
> index abbf54b..3e5abef 100755
> --- a/t/t7500-commit.sh
> +++ b/t/t7500-commit.sh
> @@ -93,4 +93,17 @@ test_expect_success 'commit message from file should override template' '
>         commit_msg_is "standard input msg"
>  '
>  
> +test_expect_success 'using GIT_INDEX_FILE' '
> +
> +       echo "some new content" >file &&
> +       GIT_INDEX_FILE=.git/another_index git add file &&
> +       GIT_INDEX_FILE=.git/another_index \
> +               git commit -m "commit using another index" &&

Tests that git-commit does not choke on committing the addion a
new 'file'.

> +       git reset HEAD &&
> +       git diff HEAD -- file >current &&
> +       touch empty-file &&
> +       diff empty-file current

Clobbers the index that the above GIT_INDEX_FILE trick should
not have touched before making sure of that, which is bad, and
then makes sure that the new file actually has the right
contents.

So, what I would suggest is:

 * Your "GIT_INDEX_FILE=... git-commit" test -- git-commit
   should not fail;

 + Test that the path you modified in the above commit (in this
   case, 'file') matches between index you used in the commit
   and the resulting commit;

 * Test that the path you modified in the above commit matches
   between the HEAD, the alternate index and the work tree (your
   latter test).

 + Test that the original index the above wanted to preserve was
   not clobbered by git-commit;

 + Test git-commit runs sensibly even when it is given a
   nonexistent file as GIT_INDEX_FILE.

Perhaps like this, instead of your patch to t/t7500:

	test_expect_success 'using alternate GIT_INDEX_FILE (1)' '
	
		cp .git/index saved-index &&
		(
			echo some new content >file &&
		        GIT_INDEX_FILE=.git/another_index &&
			export GIT_INDEX_FILE &&
			git add file &&
			git commit -m "commit using another index" &&
			git diff-index --exit-code HEAD &&
			git diff-files --exit-code
		) &&
		cmp .git/index saved-index >/dev/null
	
	'
	
	test_expect_success 'using alternate GIT_INDEX_FILE (2)' '
	
		cp .git/index saved-index &&
		(
			rm -f .git/no-such-index &&
			GIT_INDEX_FILE=.git/no-such-index &&
			export GIT_INDEX_FILE &&
			git commit -m "commit using nonexistent index" &&
			test -z "$(git ls-files)" &&
			test -z "$(git ls-tree HEAD)"
	
		) &&
		cmp .git/index saved-index >/dev/null
	
	'

```

## Remi Vanicat, 2007-11-12 18:41

Subject: Re: [PATCH v3] Make GIT_INDEX_FILE apply to git-commit
Message-ID: <87d4ufi9wm.dlv@vanicat.homelinux.org>
URL: https://gitlist.dev/e/87d4ufi9wm.dlv%40vanicat.homelinux.org
In-Reply-To: <7vlk94d043.fsf@gitster.siamese.dyndns.org>

```
Junio C Hamano <gitster@pobox.com> writes:

> Rémi Vanicat <vanicat@debian.org> writes:
>
>> @@ -26,7 +26,7 @@ refuse_partial () {
>>  }
>>  
>>  TMP_INDEX=
>> -THIS_INDEX="$GIT_DIR/index"
>> +THIS_INDEX="${GIT_INDEX_FILE:-$GIT_DIR/index}"
>>  NEXT_INDEX="$GIT_DIR/next-index$$"
>>  rm -f "$NEXT_INDEX"
>>  save_index () {
>
> This is just a "purist" question, but I wonder if we want to
> differentiate the case where GIT_INDEX_FILE is set to empty and
> GIT_INDEX_FILE is not set at all?

Well, It's my first patch to git, and I overlook it

> So, what I would suggest is:
>
>  * Your "GIT_INDEX_FILE=... git-commit" test -- git-commit
>    should not fail;
>
>  + Test that the path you modified in the above commit (in this
>    case, 'file') matches between index you used in the commit
>    and the resulting commit;
>
>  * Test that the path you modified in the above commit matches
>    between the HEAD, the alternate index and the work tree (your
>    latter test).
>
>  + Test that the original index the above wanted to preserve was
>    not clobbered by git-commit;
>
>  + Test git-commit runs sensibly even when it is given a
>    nonexistent file as GIT_INDEX_FILE.
>
> Perhaps like this, instead of your patch to t/t7500:
>
> 	test_expect_success 'using alternate GIT_INDEX_FILE (1)' '
> 	
> 		cp .git/index saved-index &&
> 		(
> 			echo some new content >file &&
> 		        GIT_INDEX_FILE=.git/another_index &&
> 			export GIT_INDEX_FILE &&
> 			git add file &&
> 			git commit -m "commit using another index" &&
> 			git diff-index --exit-code HEAD &&
> 			git diff-files --exit-code
> 		) &&
> 		cmp .git/index saved-index >/dev/null
> 	
> 	'
> 	
> 	test_expect_success 'using alternate GIT_INDEX_FILE (2)' '
> 	
> 		cp .git/index saved-index &&
> 		(
> 			rm -f .git/no-such-index &&
> 			GIT_INDEX_FILE=.git/no-such-index &&
> 			export GIT_INDEX_FILE &&
> 			git commit -m "commit using nonexistent index" &&
> 			test -z "$(git ls-files)" &&
> 			test -z "$(git ls-tree HEAD)"
> 	
> 		) &&
> 		cmp .git/index saved-index >/dev/null
> 	
> 	'

Seem, good, I will use this.

-- 
Rémi Vanicat

```
