Skip to content

Commit 43f3690

Browse files
committed
Merge branch 'rv/maint-index-commit'
* rv/maint-index-commit: Make GIT_INDEX_FILE apply to git-commit
2 parents 9f16580 + 859a4db commit 43f3690

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

git-commit.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ refuse_partial () {
2626
}
2727

2828
TMP_INDEX=
29-
THIS_INDEX="$GIT_DIR/index"
29+
THIS_INDEX="${GIT_INDEX_FILE:-$GIT_DIR/index}"
3030
NEXT_INDEX="$GIT_DIR/next-index$$"
3131
rm -f "$NEXT_INDEX"
3232
save_index () {

t/t7500-commit.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,36 @@ test_expect_success 'commit message from file should override template' '
9393
commit_msg_is "standard input msg"
9494
'
9595

96+
test_expect_success 'using alternate GIT_INDEX_FILE (1)' '
97+
98+
cp .git/index saved-index &&
99+
(
100+
echo some new content >file &&
101+
GIT_INDEX_FILE=.git/another_index &&
102+
export GIT_INDEX_FILE &&
103+
git add file &&
104+
git commit -m "commit using another index" &&
105+
git diff-index --exit-code HEAD &&
106+
git diff-files --exit-code
107+
) &&
108+
cmp .git/index saved-index >/dev/null
109+
110+
'
111+
112+
test_expect_success 'using alternate GIT_INDEX_FILE (2)' '
113+
114+
cp .git/index saved-index &&
115+
(
116+
rm -f .git/no-such-index &&
117+
GIT_INDEX_FILE=.git/no-such-index &&
118+
export GIT_INDEX_FILE &&
119+
git commit -m "commit using nonexistent index" &&
120+
test -z "$(git ls-files)" &&
121+
test -z "$(git ls-tree HEAD)"
122+
123+
) &&
124+
cmp .git/index saved-index >/dev/null
125+
126+
'
127+
96128
test_done

0 commit comments

Comments
 (0)