t / t2107-update-index-basic.shon commit update-index: teach --cacheinfo a new syntax "mode,sha1,path" (ec160ae)
   1#!/bin/sh
   2
   3test_description='basic update-index tests
   4
   5Tests for command-line parsing and basic operation.
   6'
   7
   8. ./test-lib.sh
   9
  10test_expect_success 'update-index --nonsense fails' '
  11        test_must_fail git update-index --nonsense 2>msg &&
  12        cat msg &&
  13        test -s msg
  14'
  15
  16test_expect_success 'update-index --nonsense dumps usage' '
  17        test_expect_code 129 git update-index --nonsense 2>err &&
  18        test_i18ngrep "[Uu]sage: git update-index" err
  19'
  20
  21test_expect_success 'update-index -h with corrupt index' '
  22        mkdir broken &&
  23        (
  24                cd broken &&
  25                git init &&
  26                >.git/index &&
  27                test_expect_code 129 git update-index -h >usage 2>&1
  28        ) &&
  29        test_i18ngrep "[Uu]sage: git update-index" broken/usage
  30'
  31
  32test_expect_success '--cacheinfo does not accept blob null sha1' '
  33        echo content >file &&
  34        git add file &&
  35        git rev-parse :file >expect &&
  36        test_must_fail git update-index --cacheinfo 100644 $_z40 file &&
  37        git rev-parse :file >actual &&
  38        test_cmp expect actual
  39'
  40
  41test_expect_success '--cacheinfo does not accept gitlink null sha1' '
  42        git init submodule &&
  43        (cd submodule && test_commit foo) &&
  44        git add submodule &&
  45        git rev-parse :submodule >expect &&
  46        test_must_fail git update-index --cacheinfo 160000 $_z40 submodule &&
  47        git rev-parse :submodule >actual &&
  48        test_cmp expect actual
  49'
  50
  51test_expect_success '--cacheinfo mode,sha1,path (new syntax)' '
  52        echo content >file &&
  53        git hash-object -w --stdin <file >expect &&
  54
  55        git update-index --add --cacheinfo 100644 "$(cat expect)" file &&
  56        git rev-parse :file >actual &&
  57        test_cmp expect actual &&
  58
  59        git update-index --add --cacheinfo "100644,$(cat expect),elif" &&
  60        git rev-parse :elif >actual &&
  61        test_cmp expect actual
  62'
  63
  64test_done