The eleventh batch
[git/gitster.git] / t / t9160-git-svn-preserve-empty-dirs.sh
blob36c6b1a12ffd95a1d6fe4ee4efd18a47f1581078
1 #!/bin/sh
3 # Copyright (c) 2011 Ray Chen
6 test_description='git svn test (option --preserve-empty-dirs)
8 This test uses git to clone a Subversion repository that contains empty
9 directories, and checks that corresponding directories are created in the
10 local Git repository with placeholder files.'
12 . ./lib-git-svn.sh
14 GIT_REPO=git-svn-repo
16 test_expect_success 'initialize source svn repo containing empty dirs' '
17 svn_cmd mkdir -m x "$svnrepo"/trunk &&
18 svn_cmd co "$svnrepo"/trunk "$SVN_TREE" &&
20 cd "$SVN_TREE" &&
21 mkdir -p 1 2 3/a 3/b 4 5 6 &&
22 echo "First non-empty file" > 2/file1.txt &&
23 echo "Second non-empty file" > 2/file2.txt &&
24 echo "Third non-empty file" > 3/a/file1.txt &&
25 echo "Fourth non-empty file" > 3/b/file1.txt &&
26 svn_cmd add 1 2 3 4 5 6 &&
27 svn_cmd commit -m "initial commit" &&
29 mkdir 4/a &&
30 svn_cmd add 4/a &&
31 svn_cmd commit -m "nested empty directory" &&
32 mkdir 4/a/b &&
33 svn_cmd add 4/a/b &&
34 svn_cmd commit -m "deeply nested empty directory" &&
35 mkdir 4/a/b/c &&
36 svn_cmd add 4/a/b/c &&
37 svn_cmd commit -m "really deeply nested empty directory" &&
38 echo "Kill the placeholder file" > 4/a/b/c/foo &&
39 svn_cmd add 4/a/b/c/foo &&
40 svn_cmd commit -m "Regular file to remove placeholder" &&
42 svn_cmd del 2/file2.txt &&
43 svn_cmd del 3/b &&
44 svn_cmd commit -m "delete non-last entry in directory" &&
46 svn_cmd del 2/file1.txt &&
47 svn_cmd del 3/a &&
48 svn_cmd commit -m "delete last entry in directory" &&
50 echo "Conflict file" > 5/.placeholder &&
51 mkdir 6/.placeholder &&
52 svn_cmd add 5/.placeholder 6/.placeholder &&
53 svn_cmd commit -m "Placeholder Namespace conflict"
54 ) &&
55 rm -rf "$SVN_TREE"
58 test_expect_success 'clone svn repo with --preserve-empty-dirs' '
59 git svn clone "$svnrepo"/trunk --preserve-empty-dirs "$GIT_REPO"
62 # "$GIT_REPO"/1 should only contain the placeholder file.
63 test_expect_success 'directory empty from inception' '
64 test -f "$GIT_REPO"/1/.gitignore &&
65 test $(find "$GIT_REPO"/1 -type f | wc -l) = "1"
68 # "$GIT_REPO"/2 and "$GIT_REPO"/3 should only contain the placeholder file.
69 test_expect_success 'directory empty from subsequent svn commit' '
70 test -f "$GIT_REPO"/2/.gitignore &&
71 test $(find "$GIT_REPO"/2 -type f | wc -l) = "1" &&
72 test -f "$GIT_REPO"/3/.gitignore &&
73 test $(find "$GIT_REPO"/3 -type f | wc -l) = "1"
76 # No placeholder files should exist in "$GIT_REPO"/4, even though one was
77 # generated for every sub-directory at some point in the repo's history.
78 test_expect_success 'add entry to previously empty directory' '
79 test $(find "$GIT_REPO"/4 -type f | wc -l) = "1" &&
80 test -f "$GIT_REPO"/4/a/b/c/foo
83 # The HEAD~2 commit should not have introduced .gitignore placeholder files.
84 test_expect_success 'remove non-last entry from directory' '
86 cd "$GIT_REPO" &&
87 git checkout HEAD~2
88 ) &&
89 test_path_is_missing "$GIT_REPO"/2/.gitignore &&
90 test_path_is_missing "$GIT_REPO"/3/.gitignore
93 # After re-cloning the repository with --placeholder-file specified, there
94 # should be 5 files named ".placeholder" in the local Git repo.
95 test_expect_success 'clone svn repo with --placeholder-file specified' '
96 rm -rf "$GIT_REPO" &&
97 git svn clone "$svnrepo"/trunk --preserve-empty-dirs \
98 --placeholder-file=.placeholder "$GIT_REPO" &&
99 find "$GIT_REPO" -type f -name ".placeholder" &&
100 test $(find "$GIT_REPO" -type f -name ".placeholder" | wc -l) = "5"
103 # "$GIT_REPO"/5/.placeholder should be a file, and non-empty.
104 test_expect_success 'placeholder namespace conflict with file' '
105 test -s "$GIT_REPO"/5/.placeholder
108 # "$GIT_REPO"/6/.placeholder should be a directory, and the "$GIT_REPO"/6 tree
109 # should only contain one file: the placeholder.
110 test_expect_success 'placeholder namespace conflict with directory' '
111 test -d "$GIT_REPO"/6/.placeholder &&
112 test -f "$GIT_REPO"/6/.placeholder/.placeholder &&
113 test $(find "$GIT_REPO"/6 -type f | wc -l) = "1"
116 # Prepare a second set of svn commits to test persistence during rebase.
117 test_expect_success 'second set of svn commits and rebase' '
118 svn_cmd co "$svnrepo"/trunk "$SVN_TREE" &&
120 cd "$SVN_TREE" &&
121 mkdir -p 7 &&
122 echo "This should remove placeholder" > 1/file1.txt &&
123 echo "This should not remove placeholder" > 5/file1.txt &&
124 svn_cmd add 7 1/file1.txt 5/file1.txt &&
125 svn_cmd commit -m "subsequent svn commit for persistence tests"
126 ) &&
127 rm -rf "$SVN_TREE" &&
129 cd "$GIT_REPO" &&
130 git svn rebase
134 # Check that --preserve-empty-dirs and --placeholder-file flag state
135 # stays persistent over multiple invocations.
136 test_expect_success 'flag persistence during subsqeuent rebase' '
137 test -f "$GIT_REPO"/7/.placeholder &&
138 test $(find "$GIT_REPO"/7 -type f | wc -l) = "1"
141 # Check that placeholder files are properly removed when unnecessary,
142 # even across multiple invocations.
143 test_expect_success 'placeholder list persistence during subsqeuent rebase' '
144 test -f "$GIT_REPO"/1/file1.txt &&
145 test $(find "$GIT_REPO"/1 -type f | wc -l) = "1" &&
147 test -f "$GIT_REPO"/5/file1.txt &&
148 test -f "$GIT_REPO"/5/.placeholder &&
149 test $(find "$GIT_REPO"/5 -type f | wc -l) = "2"
152 test_done