Fifth batch for 2.20
[git/git.git] / t / t2001-checkout-cache-clash.sh
CommitLineData
368f99d5
JH
1#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano
4#
5
5be60078 6test_description='git checkout-index test.
368f99d5
JH
7
8This test registers the following filesystem structure in the cache:
9
10 path0/file0 - a file in a directory
11 path1/file1 - a file in a directory
12
13and attempts to check it out when the work tree has:
14
15 path0/file0 - a file in a directory
16 path1 - a symlink pointing at "path0"
17
18Checkout cache should fail to extract path1/file1 because the leading
19path path1 is occupied by a non-directory. With "-f" it should remove
20the symlink path1 and create directory path1 and file path1/file1.
21'
22. ./test-lib.sh
23
24show_files() {
25 # show filesystem files, just [-dl] for type and name
26 find path? -ls |
27 sed -e 's/^[0-9]* * [0-9]* * \([-bcdl]\)[^ ]* *[0-9]* *[^ ]* *[^ ]* *[0-9]* [A-Z][a-z][a-z] [0-9][0-9] [^ ]* /fs: \1 /'
28 # what's in the cache, just mode and name
5be60078 29 git ls-files --stage |
368f99d5
JH
30 sed -e 's/^\([0-9]*\) [0-9a-f]* [0-3] /ca: \1 /'
31 # what's in the tree, just mode and name.
5be60078 32 git ls-tree -r "$1" |
368f99d5
JH
33 sed -e 's/^\([0-9]*\) [^ ]* [0-9a-f]* /tr: \1 /'
34}
35
36mkdir path0
37date >path0/file0
38test_expect_success \
5be60078
JH
39 'git update-index --add path0/file0' \
40 'git update-index --add path0/file0'
368f99d5 41test_expect_success \
5be60078
JH
42 'writing tree out with git write-tree' \
43 'tree1=$(git write-tree)'
368f99d5
JH
44test_debug 'show_files $tree1'
45
46mkdir path1
47date >path1/file1
48test_expect_success \
5be60078
JH
49 'git update-index --add path1/file1' \
50 'git update-index --add path1/file1'
368f99d5 51test_expect_success \
5be60078
JH
52 'writing tree out with git write-tree' \
53 'tree2=$(git write-tree)'
368f99d5
JH
54test_debug 'show_files $tree2'
55
56rm -fr path1
57test_expect_success \
58 'read previously written tree and checkout.' \
5be60078 59 'git read-tree -m $tree1 && git checkout-index -f -a'
368f99d5
JH
60test_debug 'show_files $tree1'
61
889c6f0e
JS
62test_expect_success \
63 'add a symlink' \
64 'test_ln_s_add path0 path1'
368f99d5 65test_expect_success \
5be60078
JH
66 'writing tree out with git write-tree' \
67 'tree3=$(git write-tree)'
368f99d5
JH
68test_debug 'show_files $tree3'
69
70# Morten says "Got that?" here.
71# Test begins.
72
73test_expect_success \
74 'read previously written tree and checkout.' \
5be60078 75 'git read-tree $tree2 && git checkout-index -f -a'
36071af3 76test_debug 'show_files $tree2'
368f99d5 77
886856ab
JH
78test_expect_success \
79 'checking out conflicting path with -f' \
80 'test ! -h path0 && test -d path0 &&
81 test ! -h path1 && test -d path1 &&
82 test ! -h path0/file0 && test -f path0/file0 &&
83 test ! -h path1/file1 && test -f path1/file1'
368f99d5
JH
84
85test_done