interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / t / t2000-conflict-when-checking-files-out.sh

96 lines · 2707 bytes Raw Blame History
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
24. ./test-lib.sh
25
26
27test_expect_success 'prepare files path0 and path1/file1' '
28 date >path0 &&
29 mkdir path1 &&
30 date >path1/file1 &&
31 git update-index --add path0 path1/file1
32'
33
34test_expect_success 'prepare working tree files with D/F conflicts' '
35 rm -fr path0 path1 &&
36 mkdir path0 &&
37 date >path0/file0 &&
38 date >path1
39'
40
41test_expect_success 'git checkout-index without -f should fail on conflicting work tree.' '
42 test_must_fail git checkout-index -a
43'
44
45test_expect_success 'git checkout-index with -f should succeed.' '
46 git checkout-index -f -a &&
47 test_path_is_file path0 &&
48 test_path_is_dir path1 &&
49 test_path_is_file path1/file1
50'
51
52test_expect_success SYMLINKS 'checkout-index -f twice with --prefix' '
53 mkdir -p tar/get &&
54 ln -s tar/get there &&
55 echo first &&
56 git checkout-index -a -f --prefix=there/ &&
57 echo second &&
58 git checkout-index -a -f --prefix=there/
59'
60
61# The second test registers the following filesystem structure in the cache:
62#
63# path2/file0 - a file in a directory
64# path3/file1 - a file in a directory
65#
66# and attempts to check it out when the work tree has:
67#
68# path2/file0 - a file in a directory
69# path3 - a symlink pointing at "path2"
70#
71# Checkout cache should fail to extract path3/file1 because the leading
72# path path3 is occupied by a non-directory. With "-f" it should remove
73# the symlink path3 and create directory path3 and file path3/file1.
74
75test_expect_success 'checkout-index -f resolves symlink conflict on leading path' '
76 mkdir path2 &&
77 date >path2/file0 &&
78 git update-index --add path2/file0 &&
79 tree1=$(git write-tree) &&
80 mkdir path3 &&
81 date >path3/file1 &&
82 git update-index --add path3/file1 &&
83 tree2=$(git write-tree) &&
84 rm -fr path3 &&
85 git read-tree -m $tree1 &&
86 git checkout-index -f -a &&
87 test_ln_s_add path2 path3 &&
88 git read-tree $tree2 &&
89 git checkout-index -f -a &&
90 test_path_is_dir_not_symlink path2 &&
91 test_path_is_dir_not_symlink path3 &&
92 test_path_is_file_not_symlink path2/file0 &&
93 test_path_is_file_not_symlink path3/file1
94'
95
96test_done