t / t5001-archive-attr.shon commit Merge branch 'js/mingw-spawn-with-spaces-in-path' into maint (2f72ebf)
   1#!/bin/sh
   2
   3test_description='git archive attribute tests'
   4
   5. ./test-lib.sh
   6
   7SUBSTFORMAT='%H (%h)%n'
   8
   9test_expect_exists() {
  10        test_expect_${2:-success} " $1 exists" "test -e $1"
  11}
  12
  13test_expect_missing() {
  14        test_expect_${2:-success} " $1 does not exist" "test ! -e $1"
  15}
  16
  17extract_tar_to_dir () {
  18        (mkdir "$1" && cd "$1" && "$TAR" xf -) <"$1.tar"
  19}
  20
  21test_expect_success 'setup' '
  22        echo ignored >ignored &&
  23        echo ignored export-ignore >>.git/info/attributes &&
  24        git add ignored &&
  25
  26        echo ignored by tree >ignored-by-tree &&
  27        echo ignored-by-tree export-ignore >.gitattributes &&
  28        mkdir ignored-by-tree.d &&
  29        >ignored-by-tree.d/file &&
  30        echo ignored-by-tree.d export-ignore >>.gitattributes &&
  31        git add ignored-by-tree ignored-by-tree.d .gitattributes &&
  32
  33        echo ignored by worktree >ignored-by-worktree &&
  34        echo ignored-by-worktree export-ignore >.gitattributes &&
  35        git add ignored-by-worktree &&
  36
  37        mkdir excluded-by-pathspec.d &&
  38        >excluded-by-pathspec.d/file &&
  39        git add excluded-by-pathspec.d &&
  40
  41        printf "A\$Format:%s\$O" "$SUBSTFORMAT" >nosubstfile &&
  42        printf "A\$Format:%s\$O" "$SUBSTFORMAT" >substfile1 &&
  43        printf "A not substituted O" >substfile2 &&
  44        echo "substfile?" export-subst >>.git/info/attributes &&
  45        git add nosubstfile substfile1 substfile2 &&
  46
  47        git commit -m. &&
  48
  49        git clone --bare . bare &&
  50        cp .git/info/attributes bare/info/attributes
  51'
  52
  53test_expect_success 'git archive' '
  54        git archive HEAD >archive.tar &&
  55        (mkdir archive && cd archive && "$TAR" xf -) <archive.tar
  56'
  57
  58test_expect_missing     archive/ignored
  59test_expect_missing     archive/ignored-by-tree
  60test_expect_missing     archive/ignored-by-tree.d
  61test_expect_missing     archive/ignored-by-tree.d/file
  62test_expect_exists      archive/ignored-by-worktree
  63test_expect_exists      archive/excluded-by-pathspec.d
  64test_expect_exists      archive/excluded-by-pathspec.d/file
  65
  66test_expect_success 'git archive with pathspec' '
  67        git archive HEAD ":!excluded-by-pathspec.d" >archive-pathspec.tar &&
  68        extract_tar_to_dir archive-pathspec
  69'
  70
  71test_expect_missing     archive-pathspec/ignored
  72test_expect_missing     archive-pathspec/ignored-by-tree
  73test_expect_missing     archive-pathspec/ignored-by-tree.d
  74test_expect_missing     archive-pathspec/ignored-by-tree.d/file
  75test_expect_exists      archive-pathspec/ignored-by-worktree
  76test_expect_missing     archive-pathspec/excluded-by-pathspec.d
  77test_expect_missing     archive-pathspec/excluded-by-pathspec.d/file
  78
  79test_expect_success 'git archive with wildcard pathspec' '
  80        git archive HEAD ":!excluded-by-p*" >archive-pathspec-wildcard.tar &&
  81        extract_tar_to_dir archive-pathspec-wildcard
  82'
  83
  84test_expect_missing     archive-pathspec-wildcard/ignored
  85test_expect_missing     archive-pathspec-wildcard/ignored-by-tree
  86test_expect_missing     archive-pathspec-wildcard/ignored-by-tree.d
  87test_expect_missing     archive-pathspec-wildcard/ignored-by-tree.d/file
  88test_expect_exists      archive-pathspec-wildcard/ignored-by-worktree
  89test_expect_missing     archive-pathspec-wildcard/excluded-by-pathspec.d
  90test_expect_missing     archive-pathspec-wildcard/excluded-by-pathspec.d/file
  91
  92test_expect_success 'git archive with worktree attributes' '
  93        git archive --worktree-attributes HEAD >worktree.tar &&
  94        (mkdir worktree && cd worktree && "$TAR" xf -) <worktree.tar
  95'
  96
  97test_expect_missing     worktree/ignored
  98test_expect_exists      worktree/ignored-by-tree
  99test_expect_missing     worktree/ignored-by-worktree
 100
 101test_expect_success 'git archive --worktree-attributes option' '
 102        git archive --worktree-attributes --worktree-attributes HEAD >worktree.tar &&
 103        (mkdir worktree2 && cd worktree2 && "$TAR" xf -) <worktree.tar
 104'
 105
 106test_expect_missing     worktree2/ignored
 107test_expect_exists      worktree2/ignored-by-tree
 108test_expect_missing     worktree2/ignored-by-worktree
 109
 110test_expect_success 'git archive vs. bare' '
 111        (cd bare && git archive HEAD) >bare-archive.tar &&
 112        test_cmp_bin archive.tar bare-archive.tar
 113'
 114
 115test_expect_success 'git archive with worktree attributes, bare' '
 116        (cd bare && git archive --worktree-attributes HEAD) >bare-worktree.tar &&
 117        (mkdir bare-worktree && cd bare-worktree && "$TAR" xf -) <bare-worktree.tar
 118'
 119
 120test_expect_missing     bare-worktree/ignored
 121test_expect_exists      bare-worktree/ignored-by-tree
 122test_expect_exists      bare-worktree/ignored-by-worktree
 123
 124test_expect_success 'export-subst' '
 125        git log "--pretty=format:A${SUBSTFORMAT}O" HEAD >substfile1.expected &&
 126        test_cmp nosubstfile archive/nosubstfile &&
 127        test_cmp substfile1.expected archive/substfile1 &&
 128        test_cmp substfile2 archive/substfile2
 129'
 130
 131test_done