Test 'commit --only' after 'checkout --orphan'

There are some index handling subtleties in 'commit --only' that are best tested when we have an existing index, but an unborn or empty HEAD. These circumstances are easily produced by 'checkout --orphan', but we did not previously have a test for it. The main expected failure mode would be: erroneously loading the existing index contents when building the temporary index that is used for --only. Cf. http://article.gmane.org/gmane.comp.version-control.git/225969 and subsequent discussion. Signed-off-by: Thomas Rast <trast@inf.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Thomas Rast committed Jun 1, 2013 at 13:02 UTC f0c73200e86b6166596f45ce32b7f04291074182
1 file changed +13
t/t7501-commit.sh
+13
@@ -524,4 +524,17 @@ test_expect_success 'commit a file whose name is a dash' '
524 test_i18ngrep " changed, 5 insertions" output
525 '
526
527 +test_expect_success '--only works on to-be-born branch' '
528 + # This test relies on having something in the index, as it
529 + # would not otherwise actually prove much. So check this.
530 + test -n "$(git ls-files)" &&
531 + git checkout --orphan orphan &&
532 + echo foo >newfile &&
533 + git add newfile &&
534 + git commit --only newfile -m"--only on unborn branch" &&
535 + echo newfile >expected &&
536 + git ls-tree -r --name-only HEAD >actual &&
537 + test_cmp expected actual
538 +'
539 +
540 test_done