]> git.ipfire.org Git - thirdparty/git.git/blame - t/t2000-conflict-when-checking-files-out.sh
Start the 2.46 cycle
[thirdparty/git.git] / t / t2000-conflict-when-checking-files-out.sh
CommitLineData
b684062f
SS
1#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano
4#
5
6test_description='git conflicts when checking files out test.'
7
8# The first test registers the following filesystem structure in the
9# cache:
10#
11# path0 - a file
12# path1/file1 - a file in a directory
13#
14# And then tries to checkout in a work tree that has the following:
15#
16# path0/file0 - a file in a directory
17# path1 - a file
18#
19# The git checkout-index command should fail when attempting to checkout
20# path0, finding it is occupied by a directory, and path1/file1, finding
21# path1 is occupied by a non-directory. With "-f" flag, it should remove
22# the conflicting paths and succeed.
23
d96fb140 24TEST_PASSES_SANITIZE_LEAK=true
b684062f
SS
25. ./test-lib.sh
26
27show_files() {
28 # show filesystem files, just [-dl] for type and name
29 find path? -ls |
30 sed -e 's/^[0-9]* * [0-9]* * \([-bcdl]\)[^ ]* *[0-9]* *[^ ]* *[^ ]* *[0-9]* [A-Z][a-z][a-z] [0-9][0-9] [^ ]* /fs: \1 /'
31 # what's in the cache, just mode and name
32 git ls-files --stage |
33 sed -e 's/^\([0-9]*\) [0-9a-f]* [0-3] /ca: \1 /'
34 # what's in the tree, just mode and name.
35 git ls-tree -r "$1" |
36 sed -e 's/^\([0-9]*\) [^ ]* [0-9a-f]* /tr: \1 /'
37}
38
39date >path0
40mkdir path1
41date >path1/file1
42
43test_expect_success \
44 'git update-index --add various paths.' \
45 'git update-index --add path0 path1/file1'
46
47rm -fr path0 path1
48mkdir path0
49date >path0/file0
50date >path1
51
52test_expect_success \
53 'git checkout-index without -f should fail on conflicting work tree.' \
54 'test_must_fail git checkout-index -a'
55
56test_expect_success \
57 'git checkout-index with -f should succeed.' \
58 'git checkout-index -f -a'
59
60test_expect_success \
61 'git checkout-index conflicting paths.' \
62 'test -f path0 && test -d path1 && test -f path1/file1'
63
64test_expect_success SYMLINKS 'checkout-index -f twice with --prefix' '
65 mkdir -p tar/get &&
66 ln -s tar/get there &&
67 echo first &&
68 git checkout-index -a -f --prefix=there/ &&
69 echo second &&
70 git checkout-index -a -f --prefix=there/
71'
72
73# The second test registers the following filesystem structure in the cache:
74#
75# path2/file0 - a file in a directory
76# path3/file1 - a file in a directory
77#
78# and attempts to check it out when the work tree has:
79#
80# path2/file0 - a file in a directory
81# path3 - a symlink pointing at "path2"
82#
83# Checkout cache should fail to extract path3/file1 because the leading
84# path path3 is occupied by a non-directory. With "-f" it should remove
85# the symlink path3 and create directory path3 and file path3/file1.
86
87mkdir path2
88date >path2/file0
89test_expect_success \
90 'git update-index --add path2/file0' \
91 'git update-index --add path2/file0'
92test_expect_success \
93 'writing tree out with git write-tree' \
94 'tree1=$(git write-tree)'
95test_debug 'show_files $tree1'
96
97mkdir path3
98date >path3/file1
99test_expect_success \
100 'git update-index --add path3/file1' \
101 'git update-index --add path3/file1'
102test_expect_success \
103 'writing tree out with git write-tree' \
104 'tree2=$(git write-tree)'
105test_debug 'show_files $tree2'
106
107rm -fr path3
108test_expect_success \
109 'read previously written tree and checkout.' \
110 'git read-tree -m $tree1 && git checkout-index -f -a'
111test_debug 'show_files $tree1'
112
113test_expect_success \
114 'add a symlink' \
115 'test_ln_s_add path2 path3'
116test_expect_success \
117 'writing tree out with git write-tree' \
118 'tree3=$(git write-tree)'
119test_debug 'show_files $tree3'
120
121# Morten says "Got that?" here.
122# Test begins.
123
124test_expect_success \
125 'read previously written tree and checkout.' \
126 'git read-tree $tree2 && git checkout-index -f -a'
127test_debug 'show_files $tree2'
128
129test_expect_success \
130 'checking out conflicting path with -f' \
131 'test ! -h path2 && test -d path2 &&
132 test ! -h path3 && test -d path3 &&
133 test ! -h path2/file0 && test -f path2/file0 &&
134 test ! -h path3/file1 && test -f path3/file1'
135
136test_done