t / t5004-archive-corner-cases.shon commit revision.c: treat A...B merge bases as if manually specified (a765499)
   1#!/bin/sh
   2
   3test_description='test corner cases of git-archive'
   4. ./test-lib.sh
   5
   6test_expect_success 'create commit with empty tree' '
   7        git commit --allow-empty -m foo
   8'
   9
  10# Make a dir and clean it up afterwards
  11make_dir() {
  12        mkdir "$1" &&
  13        test_when_finished "rm -rf '$1'"
  14}
  15
  16# Check that the dir given in "$1" contains exactly the
  17# set of paths given as arguments.
  18check_dir() {
  19        dir=$1; shift
  20        {
  21                echo "$dir" &&
  22                for i in "$@"; do
  23                        echo "$dir/$i"
  24                done
  25        } | sort >expect &&
  26        find "$dir" ! -name pax_global_header -print | sort >actual &&
  27        test_cmp expect actual
  28}
  29
  30test_expect_success 'tar archive of empty tree is empty' '
  31        git archive --format=tar HEAD: >empty.tar &&
  32        perl -e "print \"\\0\" x 10240" >10knuls.tar &&
  33        test_cmp 10knuls.tar empty.tar
  34'
  35
  36test_expect_success 'tar archive of empty tree with prefix' '
  37        git archive --format=tar --prefix=foo/ HEAD >prefix.tar &&
  38        make_dir extract &&
  39        "$TAR" xf prefix.tar -C extract &&
  40        check_dir extract foo
  41'
  42
  43test_expect_success UNZIP 'zip archive of empty tree is empty' '
  44        # Detect the exit code produced when our particular flavor of unzip
  45        # sees an empty archive. Infozip will generate a warning and exit with
  46        # code 1. But in the name of sanity, we do not expect other unzip
  47        # implementations to do the same thing (it would be perfectly
  48        # reasonable to exit 0, for example).
  49        #
  50        # This makes our test less rigorous on some platforms (unzip may not
  51        # handle the empty repo at all, making our later check of its exit code
  52        # a no-op). But we cannot do anything reasonable except skip the test
  53        # on such platforms anyway, and this is the moral equivalent.
  54        "$GIT_UNZIP" "$TEST_DIRECTORY"/t5004/empty.zip
  55        expect_code=$?
  56
  57        git archive --format=zip HEAD >empty.zip &&
  58        make_dir extract &&
  59        (
  60                cd extract &&
  61                test_expect_code $expect_code "$GIT_UNZIP" ../empty.zip
  62        ) &&
  63        check_dir extract
  64'
  65
  66test_expect_success UNZIP 'zip archive of empty tree with prefix' '
  67        # We do not have to play exit-code tricks here, because our
  68        # result should not be empty; it has a directory in it.
  69        git archive --format=zip --prefix=foo/ HEAD >prefix.zip &&
  70        make_dir extract &&
  71        (
  72                cd extract &&
  73                "$GIT_UNZIP" ../prefix.zip
  74        ) &&
  75        check_dir extract foo
  76'
  77
  78test_expect_success 'archive complains about pathspec on empty tree' '
  79        test_must_fail git archive --format=tar HEAD -- foo >/dev/null
  80'
  81
  82test_expect_success 'create a commit with an empty subtree' '
  83        empty_tree=$(git hash-object -t tree /dev/null) &&
  84        root_tree=$(printf "040000 tree $empty_tree\tsub\n" | git mktree)
  85'
  86
  87test_expect_success 'archive empty subtree with no pathspec' '
  88        git archive --format=tar $root_tree >subtree-all.tar &&
  89        make_dir extract &&
  90        "$TAR" xf subtree-all.tar -C extract &&
  91        check_dir extract sub
  92'
  93
  94test_expect_success 'archive empty subtree by direct pathspec' '
  95        git archive --format=tar $root_tree -- sub >subtree-path.tar &&
  96        make_dir extract &&
  97        "$TAR" xf subtree-path.tar -C extract &&
  98        check_dir extract sub
  99'
 100
 101test_done