t / t2022-checkout-paths.shon commit Merge branch 'jk/repo-init-cleanup' (b4a1eec)
   1#!/bin/sh
   2
   3test_description='checkout $tree -- $paths'
   4. ./test-lib.sh
   5
   6test_expect_success setup '
   7        mkdir dir &&
   8        >dir/master &&
   9        echo common >dir/common &&
  10        git add dir/master dir/common &&
  11        test_tick && git commit -m "master has dir/master" &&
  12        git checkout -b next &&
  13        git mv dir/master dir/next0 &&
  14        echo next >dir/next1 &&
  15        git add dir &&
  16        test_tick && git commit -m "next has dir/next but not dir/master"
  17'
  18
  19test_expect_success 'checking out paths out of a tree does not clobber unrelated paths' '
  20        git checkout next &&
  21        git reset --hard &&
  22        rm dir/next0 &&
  23        cat dir/common >expect.common &&
  24        echo modified >expect.next1 &&
  25        cat expect.next1 >dir/next1 &&
  26        echo untracked >expect.next2 &&
  27        cat expect.next2 >dir/next2 &&
  28
  29        git checkout master dir &&
  30
  31        test_cmp expect.common dir/common &&
  32        test_path_is_file dir/master &&
  33        git diff --exit-code master dir/master &&
  34
  35        test_path_is_missing dir/next0 &&
  36        test_cmp expect.next1 dir/next1 &&
  37        test_path_is_file dir/next2 &&
  38        test_must_fail git ls-files --error-unmatch dir/next2 &&
  39        test_cmp expect.next2 dir/next2
  40'
  41
  42test_expect_success 'do not touch unmerged entries matching $path but not in $tree' '
  43        git checkout next &&
  44        git reset --hard &&
  45
  46        cat dir/common >expect.common &&
  47        EMPTY_SHA1=$(git hash-object -w --stdin </dev/null) &&
  48        git rm dir/next0 &&
  49        cat >expect.next0 <<-EOF &&
  50        100644 $EMPTY_SHA1 1    dir/next0
  51        100644 $EMPTY_SHA1 2    dir/next0
  52        EOF
  53        git update-index --index-info <expect.next0 &&
  54
  55        git checkout master dir &&
  56
  57        test_cmp expect.common dir/common &&
  58        test_path_is_file dir/master &&
  59        git diff --exit-code master dir/master &&
  60        git ls-files -s dir/next0 >actual.next0 &&
  61        test_cmp expect.next0 actual.next0
  62'
  63
  64test_expect_success 'do not touch files that are already up-to-date' '
  65        git reset --hard &&
  66        echo one >file1 &&
  67        echo two >file2 &&
  68        git add file1 file2 &&
  69        git commit -m base &&
  70        echo modified >file1 &&
  71        test-tool chmtime =1000000000 file2 &&
  72        git update-index -q --refresh &&
  73        git checkout HEAD -- file1 file2 &&
  74        echo one >expect &&
  75        test_cmp expect file1 &&
  76        echo "1000000000" >expect &&
  77        test-tool chmtime --get file2 >actual &&
  78        test_cmp expect actual
  79'
  80
  81test_expect_success 'checkout HEAD adds deleted intent-to-add file back to index' '
  82        echo "nonempty" >nonempty &&
  83        >empty &&
  84        git add nonempty empty &&
  85        git commit -m "create files to be deleted" &&
  86        git rm --cached nonempty empty &&
  87        git add -N nonempty empty &&
  88        git checkout HEAD nonempty empty &&
  89        git diff --cached --exit-code
  90'
  91
  92test_done