#!/bin/sh global test_description := ''basic update-index tests Tests for command-line parsing and basic operation. '' source ./test-lib.sh test_expect_success 'update-index --nonsense fails' ' test_must_fail git update-index --nonsense 2>msg && cat msg && test -s msg ' test_expect_success 'update-index --nonsense dumps usage' ' test_expect_code 129 git update-index --nonsense 2>err && test_i18ngrep "[Uu]sage: git update-index" err ' test_expect_success 'update-index -h with corrupt index' ' mkdir broken && ( cd broken && git init && >.git/index && test_expect_code 129 git update-index -h >usage 2>&1 ) && test_i18ngrep "[Uu]sage: git update-index" broken/usage ' test_expect_success '--cacheinfo complains of missing arguments' ' test_must_fail git update-index --cacheinfo ' test_expect_success '--cacheinfo does not accept blob null sha1' ' echo content >file && git add file && git rev-parse :file >expect && test_must_fail git update-index --cacheinfo 100644 $_z40 file && git rev-parse :file >actual && test_cmp expect actual ' test_expect_success '--cacheinfo does not accept gitlink null sha1' ' git init submodule && (cd submodule && test_commit foo) && git add submodule && git rev-parse :submodule >expect && test_must_fail git update-index --cacheinfo 160000 $_z40 submodule && git rev-parse :submodule >actual && test_cmp expect actual ' test_expect_success '--cacheinfo mode,sha1,path (new syntax)' ' echo content >file && git hash-object -w --stdin expect && git update-index --add --cacheinfo 100644 "$(cat expect)" file && git rev-parse :file >actual && test_cmp expect actual && git update-index --add --cacheinfo "100644,$(cat expect),elif" && git rev-parse :elif >actual && test_cmp expect actual ' test_expect_success '.lock files cleaned up' ' mkdir cleanup && ( cd cleanup && mkdir worktree && git init repo && cd repo && git config core.worktree ../../worktree && # --refresh triggers late setup_work_tree, # active_cache_changed is zero, rollback_lock_file fails git update-index --refresh && ! test -f .git/index.lock ) ' test_expect_success '--chmod=+x and chmod=-x in the same argument list' ' >A && >B && git add A B && git update-index --chmod=+x A --chmod=-x B && cat >expect <<-\EOF && 100755 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 A 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 B EOF git ls-files --stage A B >actual && test_cmp expect actual ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: { (SQ <"basic update-index tests\n"> <"\n"> <"Tests for command-line parsing and basic operation.\n"> ) } spids: [4] ) ] spids: [4] ) (C {(.)} {(./test-lib.sh)}) (C {(test_expect_success)} {(SQ <"update-index --nonsense fails">)} { (SQ <"\n"> <"\ttest_must_fail git update-index --nonsense 2>msg &&\n"> <"\tcat msg &&\n"> <"\ttest -s msg\n"> ) } ) (C {(test_expect_success)} {(SQ <"update-index --nonsense dumps usage">)} { (SQ <"\n"> <"\ttest_expect_code 129 git update-index --nonsense 2>err &&\n"> <"\ttest_i18ngrep \"[Uu]sage: git update-index\" err\n"> ) } ) (C {(test_expect_success)} {(SQ <"update-index -h with corrupt index">)} { (SQ <"\n"> <"\tmkdir broken &&\n"> <"\t(\n"> <"\t\tcd broken &&\n"> <"\t\tgit init &&\n"> <"\t\t>.git/index &&\n"> <"\t\ttest_expect_code 129 git update-index -h >usage 2>&1\n"> <"\t) &&\n"> <"\ttest_i18ngrep \"[Uu]sage: git update-index\" broken/usage\n"> ) } ) (C {(test_expect_success)} {(SQ <"--cacheinfo complains of missing arguments">)} {(SQ <"\n"> <"\ttest_must_fail git update-index --cacheinfo\n">)} ) (C {(test_expect_success)} {(SQ <"--cacheinfo does not accept blob null sha1">)} { (SQ <"\n"> <"\techo content >file &&\n"> <"\tgit add file &&\n"> <"\tgit rev-parse :file >expect &&\n"> <"\ttest_must_fail git update-index --cacheinfo 100644 $_z40 file &&\n"> <"\tgit rev-parse :file >actual &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"--cacheinfo does not accept gitlink null sha1">)} { (SQ <"\n"> <"\tgit init submodule &&\n"> <"\t(cd submodule && test_commit foo) &&\n"> <"\tgit add submodule &&\n"> <"\tgit rev-parse :submodule >expect &&\n"> <"\ttest_must_fail git update-index --cacheinfo 160000 $_z40 submodule &&\n"> <"\tgit rev-parse :submodule >actual &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"--cacheinfo mode,sha1,path (new syntax)">)} { (SQ <"\n"> <"\techo content >file &&\n"> <"\tgit hash-object -w --stdin expect &&\n"> <"\n"> <"\tgit update-index --add --cacheinfo 100644 \"$(cat expect)\" file &&\n"> <"\tgit rev-parse :file >actual &&\n"> <"\ttest_cmp expect actual &&\n"> <"\n"> <"\tgit update-index --add --cacheinfo \"100644,$(cat expect),elif\" &&\n"> <"\tgit rev-parse :elif >actual &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_expect_success)} {(SQ <".lock files cleaned up">)} { (SQ <"\n"> <"\tmkdir cleanup &&\n"> <"\t(\n"> <"\tcd cleanup &&\n"> <"\tmkdir worktree &&\n"> <"\tgit init repo &&\n"> <"\tcd repo &&\n"> <"\tgit config core.worktree ../../worktree &&\n"> <"\t# --refresh triggers late setup_work_tree,\n"> <"\t# active_cache_changed is zero, rollback_lock_file fails\n"> <"\tgit update-index --refresh &&\n"> <"\t! test -f .git/index.lock\n"> <"\t)\n"> ) } ) (C {(test_expect_success)} {(SQ <"--chmod=+x and chmod=-x in the same argument list">)} { (SQ <"\n"> <"\t>A &&\n"> <"\t>B &&\n"> <"\tgit add A B &&\n"> <"\tgit update-index --chmod=+x A --chmod=-x B &&\n"> <"\tcat >expect <<-\\EOF &&\n"> <"\t100755 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0\tA\n"> <"\t100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0\tB\n"> <"\tEOF\n"> <"\tgit ls-files --stage A B >actual &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_done)}) ] )