Merge branch 'th/git-diffall'
[git/jrn.git] / t / t9160-git-svn-preserve-empty-dirs.sh
blobb4a443460476bdeb783963e5a3b488b7ef6f4ad2
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 say 'define NO_SVN_TESTS to skip git svn tests'
15 GIT_REPO=git-svn-repo
17 test_expect_success 'initialize source svn repo containing empty dirs' '
18 svn_cmd mkdir -m x "$svnrepo"/trunk &&
19 svn_cmd co "$svnrepo"/trunk "$SVN_TREE" &&
21 cd "$SVN_TREE" &&
22 mkdir -p 1 2 3/a 3/b 4 5 6 &&
23 echo "First non-empty file" > 2/file1.txt &&
24 echo "Second non-empty file" > 2/file2.txt &&
25 echo "Third non-empty file" > 3/a/file1.txt &&
26 echo "Fourth non-empty file" > 3/b/file1.txt &&
27 svn_cmd add 1 2 3 4 5 6 &&
28 svn_cmd commit -m "initial commit" &&
30 mkdir 4/a &&
31 svn_cmd add 4/a &&
32 svn_cmd commit -m "nested empty directory" &&
33 mkdir 4/a/b &&
34 svn_cmd add 4/a/b &&
35 svn_cmd commit -m "deeply nested empty directory" &&
36 mkdir 4/a/b/c &&
37 svn_cmd add 4/a/b/c &&
38 svn_cmd commit -m "really deeply nested empty directory" &&
39 echo "Kill the placeholder file" > 4/a/b/c/foo &&
40 svn_cmd add 4/a/b/c/foo &&
41 svn_cmd commit -m "Regular file to remove placeholder" &&
43 svn_cmd del 2/file2.txt &&
44 svn_cmd del 3/b &&
45 svn_cmd commit -m "delete non-last entry in directory" &&
47 svn_cmd del 2/file1.txt &&
48 svn_cmd del 3/a &&
49 svn_cmd commit -m "delete last entry in directory" &&
51 echo "Conflict file" > 5/.placeholder &&
52 mkdir 6/.placeholder &&
53 svn_cmd add 5/.placeholder 6/.placeholder &&
54 svn_cmd commit -m "Placeholder Namespace conflict"
55 ) &&
56 rm -rf "$SVN_TREE"
59 test_expect_success 'clone svn repo with --preserve-empty-dirs' '
60 git svn clone "$svnrepo"/trunk --preserve-empty-dirs "$GIT_REPO"
63 # "$GIT_REPO"/1 should only contain the placeholder file.
64 test_expect_success 'directory empty from inception' '
65 test -f "$GIT_REPO"/1/.gitignore &&
66 test $(find "$GIT_REPO"/1 -type f | wc -l) = "1"
69 # "$GIT_REPO"/2 and "$GIT_REPO"/3 should only contain the placeholder file.
70 test_expect_success 'directory empty from subsequent svn commit' '
71 test -f "$GIT_REPO"/2/.gitignore &&
72 test $(find "$GIT_REPO"/2 -type f | wc -l) = "1" &&
73 test -f "$GIT_REPO"/3/.gitignore &&
74 test $(find "$GIT_REPO"/3 -type f | wc -l) = "1"
77 # No placeholder files should exist in "$GIT_REPO"/4, even though one was
78 # generated for every sub-directory at some point in the repo's history.
79 test_expect_success 'add entry to previously empty directory' '
80 test $(find "$GIT_REPO"/4 -type f | wc -l) = "1" &&
81 test -f "$GIT_REPO"/4/a/b/c/foo
84 # The HEAD~2 commit should not have introduced .gitignore placeholder files.
85 test_expect_success 'remove non-last entry from directory' '
87 cd "$GIT_REPO" &&
88 git checkout HEAD~2
89 ) &&
90 test_must_fail test -f "$GIT_REPO"/2/.gitignore &&
91 test_must_fail test -f "$GIT_REPO"/3/.gitignore
94 # After re-cloning the repository with --placeholder-file specified, there
95 # should be 5 files named ".placeholder" in the local Git repo.
96 test_expect_success 'clone svn repo with --placeholder-file specified' '
97 rm -rf "$GIT_REPO" &&
98 git svn clone "$svnrepo"/trunk --preserve-empty-dirs \
99 --placeholder-file=.placeholder "$GIT_REPO" &&
100 find "$GIT_REPO" -type f -name ".placeholder" &&
101 test $(find "$GIT_REPO" -type f -name ".placeholder" | wc -l) = "5"
104 # "$GIT_REPO"/5/.placeholder should be a file, and non-empty.
105 test_expect_success 'placeholder namespace conflict with file' '
106 test -s "$GIT_REPO"/5/.placeholder
109 # "$GIT_REPO"/6/.placeholder should be a directory, and the "$GIT_REPO"/6 tree
110 # should only contain one file: the placeholder.
111 test_expect_success 'placeholder namespace conflict with directory' '
112 test -d "$GIT_REPO"/6/.placeholder &&
113 test -f "$GIT_REPO"/6/.placeholder/.placeholder &&
114 test $(find "$GIT_REPO"/6 -type f | wc -l) = "1"
117 # Prepare a second set of svn commits to test persistence during rebase.
118 test_expect_success 'second set of svn commits and rebase' '
119 svn_cmd co "$svnrepo"/trunk "$SVN_TREE" &&
121 cd "$SVN_TREE" &&
122 mkdir -p 7 &&
123 echo "This should remove placeholder" > 1/file1.txt &&
124 echo "This should not remove placeholder" > 5/file1.txt &&
125 svn_cmd add 7 1/file1.txt 5/file1.txt &&
126 svn_cmd commit -m "subsequent svn commit for persistence tests"
127 ) &&
128 rm -rf "$SVN_TREE" &&
130 cd "$GIT_REPO" &&
131 git svn rebase
135 # Check that --preserve-empty-dirs and --placeholder-file flag state
136 # stays persistent over multiple invocations.
137 test_expect_success 'flag persistence during subsqeuent rebase' '
138 test -f "$GIT_REPO"/7/.placeholder &&
139 test $(find "$GIT_REPO"/7 -type f | wc -l) = "1"
142 # Check that placeholder files are properly removed when unnecessary,
143 # even across multiple invocations.
144 test_expect_success 'placeholder list persistence during subsqeuent rebase' '
145 test -f "$GIT_REPO"/1/file1.txt &&
146 test $(find "$GIT_REPO"/1 -type f | wc -l) = "1" &&
148 test -f "$GIT_REPO"/5/file1.txt &&
149 test -f "$GIT_REPO"/5/.placeholder &&
150 test $(find "$GIT_REPO"/5 -type f | wc -l) = "2"
153 test_done