t / t9160-git-svn-preserve-empty-dirs.shon commit Merge branch 'sb/submodule-module-list-pathspec-fix' (4f50670)
   1#!/bin/sh
   2#
   3# Copyright (c) 2011 Ray Chen
   4#
   5
   6test_description='git svn test (option --preserve-empty-dirs)
   7
   8This test uses git to clone a Subversion repository that contains empty
   9directories, and checks that corresponding directories are created in the
  10local Git repository with placeholder files.'
  11
  12. ./lib-git-svn.sh
  13
  14say 'define NO_SVN_TESTS to skip git svn tests'
  15GIT_REPO=git-svn-repo
  16
  17test_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" &&
  20        (
  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" &&
  29
  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" &&
  42
  43                svn_cmd del 2/file2.txt &&
  44                svn_cmd del 3/b &&
  45                svn_cmd commit -m "delete non-last entry in directory" &&
  46
  47                svn_cmd del 2/file1.txt &&
  48                svn_cmd del 3/a &&
  49                svn_cmd commit -m "delete last entry in directory" &&
  50
  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"
  57'
  58
  59test_expect_success 'clone svn repo with --preserve-empty-dirs' '
  60        git svn clone "$svnrepo"/trunk --preserve-empty-dirs "$GIT_REPO"
  61'
  62
  63# "$GIT_REPO"/1 should only contain the placeholder file.
  64test_expect_success 'directory empty from inception' '
  65        test -f "$GIT_REPO"/1/.gitignore &&
  66        test $(find "$GIT_REPO"/1 -type f | wc -l) = "1"
  67'
  68
  69# "$GIT_REPO"/2 and "$GIT_REPO"/3 should only contain the placeholder file.
  70test_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"
  75'
  76
  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.
  79test_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
  82'
  83
  84# The HEAD~2 commit should not have introduced .gitignore placeholder files.
  85test_expect_success 'remove non-last entry from directory' '
  86        (
  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
  92'
  93
  94# After re-cloning the repository with --placeholder-file specified, there
  95# should be 5 files named ".placeholder" in the local Git repo.
  96test_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"
 102'
 103
 104# "$GIT_REPO"/5/.placeholder should be a file, and non-empty.
 105test_expect_success 'placeholder namespace conflict with file' '
 106        test -s "$GIT_REPO"/5/.placeholder
 107'
 108
 109# "$GIT_REPO"/6/.placeholder should be a directory, and the "$GIT_REPO"/6 tree
 110# should only contain one file: the placeholder.
 111test_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"
 115'
 116
 117# Prepare a second set of svn commits to test persistence during rebase.
 118test_expect_success 'second set of svn commits and rebase' '
 119        svn_cmd co "$svnrepo"/trunk "$SVN_TREE" &&
 120        (
 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" &&
 129        (
 130                cd "$GIT_REPO" &&
 131                git svn rebase
 132        )
 133'
 134
 135# Check that --preserve-empty-dirs and --placeholder-file flag state
 136# stays persistent over multiple invocations.
 137test_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"
 140'
 141
 142# Check that placeholder files are properly removed when unnecessary,
 143# even across multiple invocations.
 144test_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" &&
 147
 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"
 151'
 152
 153test_done