Merge branch 'fc/show-non-empty-errors-in-test'
authorJunio C Hamano <gitster@pobox.com>
Thu, 20 Jun 2013 23:02:24 +0000 (16:02 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 20 Jun 2013 23:02:24 +0000 (16:02 -0700)
* fc/show-non-empty-errors-in-test:
test: test_must_be_empty helper

1  2 
t/t3400-rebase.sh
t/t3903-stash.sh
t/t7400-submodule-basic.sh
t/test-lib-functions.sh
diff --combined t/t3400-rebase.sh
index b58fa1a23243e435f119afb9966b0a80cbc1e4d4,c1d2cbad2d3ee0ac77df9e4ff8115d1db9a7ac5c..6a5ec32a2642253cb6bb8a05ff51fecc44aa4a00
@@@ -101,14 -101,7 +101,14 @@@ test_expect_success 'HEAD was detached 
        test $(git rev-parse HEAD@{1}) != $(git rev-parse my-topic-branch@{1})
  '
  
 +test_expect_success 'rebase from ambiguous branch name' '
 +      git checkout -b topic side &&
 +      git rebase master
 +'
 +
  test_expect_success 'rebase after merge master' '
 +      git checkout --detach refs/tags/topic &&
 +      git branch -D topic &&
        git reset --hard topic &&
        git merge master &&
        git rebase master &&
@@@ -145,7 -138,8 +145,7 @@@ test_expect_success 'rebase a single mo
  '
  
  test_expect_success 'rebase is not broken by diff.renames' '
 -      git config diff.renames copies &&
 -      test_when_finished "git config --unset diff.renames" &&
 +      test_config diff.renames copies &&
        git checkout filemove &&
        GIT_TRACE=1 git rebase force-3way
  '
@@@ -185,7 -179,7 +185,7 @@@ test_expect_success 'default to @{upstr
  test_expect_success 'rebase -q is quiet' '
        git checkout -b quiet topic &&
        git rebase -q master >output.out 2>&1 &&
-       test ! -s output.out
+       test_must_be_empty output.out
  '
  
  test_expect_success 'Rebase a commit that sprinkles CRs in' '
diff --combined t/t3903-stash.sh
index 8ff039bdfaeaea7382aef7fabd329cd17ff2027d,5473e6196f359858e4bf9c008951cc90d431b270..634b2b74f49558781f612e3044d99cbc6fa3e657
@@@ -200,17 -200,17 +200,17 @@@ test_expect_success 'apply -q is quiet
        echo foo > file &&
        git stash &&
        git stash apply -q > output.out 2>&1 &&
-       test ! -s output.out
+       test_must_be_empty output.out
  '
  
  test_expect_success 'save -q is quiet' '
        git stash save --quiet > output.out 2>&1 &&
-       test ! -s output.out
+       test_must_be_empty output.out
  '
  
  test_expect_success 'pop -q is quiet' '
        git stash pop -q > output.out 2>&1 &&
-       test ! -s output.out
+       test_must_be_empty output.out
  '
  
  test_expect_success 'pop -q --index works and is quiet' '
        git stash save --quiet &&
        git stash pop -q --index > output.out 2>&1 &&
        test foo = "$(git show :file)" &&
-       test ! -s output.out
+       test_must_be_empty output.out
  '
  
  test_expect_success 'drop -q is quiet' '
        git stash &&
        git stash drop -q > output.out 2>&1 &&
-       test ! -s output.out
+       test_must_be_empty output.out
  '
  
  test_expect_success 'stash -k' '
@@@ -336,58 -336,41 +336,58 @@@ test_expect_success SYMLINKS 'stash fil
  
  # This test creates a commit with a symlink used for the following tests
  
 -test_expect_success SYMLINKS 'stash symlink to file' '
 +test_expect_success 'stash symlink to file' '
        git reset --hard &&
 -      ln -s file filelink &&
 -      git add filelink &&
 +      test_ln_s_add file filelink &&
        git commit -m "Add symlink" &&
        rm filelink &&
        cp file filelink &&
 -      git stash save "symlink to file" &&
 +      git stash save "symlink to file"
 +'
 +
 +test_expect_success SYMLINKS 'this must have re-created the symlink' '
        test -h filelink &&
 -      case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac &&
 +      case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac
 +'
 +
 +test_expect_success 'unstash must re-create the file' '
        git stash apply &&
        ! test -h filelink &&
        test bar = "$(cat file)"
  '
  
 -test_expect_success SYMLINKS 'stash symlink to file (stage rm)' '
 +test_expect_success 'stash symlink to file (stage rm)' '
        git reset --hard &&
        git rm filelink &&
        cp file filelink &&
 -      git stash save "symlink to file (stage rm)" &&
 +      git stash save "symlink to file (stage rm)"
 +'
 +
 +test_expect_success SYMLINKS 'this must have re-created the symlink' '
        test -h filelink &&
 -      case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac &&
 +      case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac
 +'
 +
 +test_expect_success 'unstash must re-create the file' '
        git stash apply &&
        ! test -h filelink &&
        test bar = "$(cat file)"
  '
  
 -test_expect_success SYMLINKS 'stash symlink to file (full stage)' '
 +test_expect_success 'stash symlink to file (full stage)' '
        git reset --hard &&
        rm filelink &&
        cp file filelink &&
        git add filelink &&
 -      git stash save "symlink to file (full stage)" &&
 +      git stash save "symlink to file (full stage)"
 +'
 +
 +test_expect_success SYMLINKS 'this must have re-created the symlink' '
        test -h filelink &&
 -      case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac &&
 +      case "$(ls -l filelink)" in *" filelink -> file") :;; *) false;; esac
 +'
 +
 +test_expect_success 'unstash must re-create the file' '
        git stash apply &&
        ! test -h filelink &&
        test bar = "$(cat file)"
index ff265353a375d02bb578fed29ea00f07dc08a6fc,0055da965ca189f8ecb220e1a916c0b6714eb2b2..f47cc7b6044ba5f745f7b80ace0fcba0c255f4e5
@@@ -78,7 -78,7 +78,7 @@@ test_expect_success 'submodule add' 
        (
                cd addtest &&
                git submodule add -q "$submodurl" submod >actual &&
-               test ! -s actual &&
+               test_must_be_empty actual &&
                echo "gitdir: ../.git/modules/submod" >expect &&
                test_cmp expect submod/.git &&
                (
@@@ -308,7 -308,7 +308,7 @@@ test_expect_success 'update should wor
  
        mkdir init &&
        git submodule update -q >update.out &&
-       test ! -s update.out &&
+       test_must_be_empty update.out &&
  
        inspect init &&
        test_cmp expect head-sha1
@@@ -696,7 -696,7 +696,7 @@@ test_expect_success 'submodule add --na
                rm -rf repo &&
                git rm repo &&
                git submodule add -q --name repo_new "$submodurl/bare.git" repo >actual &&
-               test ! -s actual &&
+               test_must_be_empty actual &&
                echo "gitdir: ../.git/modules/submod" >expect &&
                test_cmp expect submod/.git &&
                (
@@@ -757,115 -757,4 +757,115 @@@ test_expect_success 'submodule add wit
        )
  '
  
 +test_expect_success 'set up a second submodule' '
 +      git submodule add ./init2 example2 &&
 +      git commit -m "submodule example2 added"
 +'
 +
 +test_expect_success 'submodule deinit should remove the whole submodule section from .git/config' '
 +      git config submodule.example.foo bar &&
 +      git config submodule.example2.frotz nitfol &&
 +      git submodule deinit init &&
 +      test -z "$(git config --get-regexp "submodule\.example\.")" &&
 +      test -n "$(git config --get-regexp "submodule\.example2\.")" &&
 +      test -f example2/.git &&
 +      rmdir init
 +'
 +
 +test_expect_success 'submodule deinit . deinits all initialized submodules' '
 +      git submodule update --init &&
 +      git config submodule.example.foo bar &&
 +      git config submodule.example2.frotz nitfol &&
 +      test_must_fail git submodule deinit &&
 +      git submodule deinit . >actual &&
 +      test -z "$(git config --get-regexp "submodule\.example\.")" &&
 +      test -z "$(git config --get-regexp "submodule\.example2\.")" &&
 +      test_i18ngrep "Cleared directory .init" actual &&
 +      test_i18ngrep "Cleared directory .example2" actual &&
 +      rmdir init example2
 +'
 +
 +test_expect_success 'submodule deinit deinits a submodule when its work tree is missing or empty' '
 +      git submodule update --init &&
 +      rm -rf init example2/* example2/.git &&
 +      git submodule deinit init example2 >actual &&
 +      test -z "$(git config --get-regexp "submodule\.example\.")" &&
 +      test -z "$(git config --get-regexp "submodule\.example2\.")" &&
 +      test_i18ngrep ! "Cleared directory .init" actual &&
 +      test_i18ngrep "Cleared directory .example2" actual &&
 +      rmdir init
 +'
 +
 +test_expect_success 'submodule deinit fails when the submodule contains modifications unless forced' '
 +      git submodule update --init &&
 +      echo X >>init/s &&
 +      test_must_fail git submodule deinit init &&
 +      test -n "$(git config --get-regexp "submodule\.example\.")" &&
 +      test -f example2/.git &&
 +      git submodule deinit -f init >actual &&
 +      test -z "$(git config --get-regexp "submodule\.example\.")" &&
 +      test_i18ngrep "Cleared directory .init" actual &&
 +      rmdir init
 +'
 +
 +test_expect_success 'submodule deinit fails when the submodule contains untracked files unless forced' '
 +      git submodule update --init &&
 +      echo X >>init/untracked &&
 +      test_must_fail git submodule deinit init &&
 +      test -n "$(git config --get-regexp "submodule\.example\.")" &&
 +      test -f example2/.git &&
 +      git submodule deinit -f init >actual &&
 +      test -z "$(git config --get-regexp "submodule\.example\.")" &&
 +      test_i18ngrep "Cleared directory .init" actual &&
 +      rmdir init
 +'
 +
 +test_expect_success 'submodule deinit fails when the submodule HEAD does not match unless forced' '
 +      git submodule update --init &&
 +      (
 +              cd init &&
 +              git checkout HEAD^
 +      ) &&
 +      test_must_fail git submodule deinit init &&
 +      test -n "$(git config --get-regexp "submodule\.example\.")" &&
 +      test -f example2/.git &&
 +      git submodule deinit -f init >actual &&
 +      test -z "$(git config --get-regexp "submodule\.example\.")" &&
 +      test_i18ngrep "Cleared directory .init" actual &&
 +      rmdir init
 +'
 +
 +test_expect_success 'submodule deinit is silent when used on an uninitialized submodule' '
 +      git submodule update --init &&
 +      git submodule deinit init >actual &&
 +      test_i18ngrep "Submodule .example. (.*) unregistered for path .init" actual &&
 +      test_i18ngrep "Cleared directory .init" actual &&
 +      git submodule deinit init >actual &&
 +      test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
 +      test_i18ngrep "Cleared directory .init" actual &&
 +      git submodule deinit . >actual &&
 +      test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
 +      test_i18ngrep "Submodule .example2. (.*) unregistered for path .example2" actual &&
 +      test_i18ngrep "Cleared directory .init" actual &&
 +      git submodule deinit . >actual &&
 +      test_i18ngrep ! "Submodule .example. (.*) unregistered for path .init" actual &&
 +      test_i18ngrep ! "Submodule .example2. (.*) unregistered for path .example2" actual &&
 +      test_i18ngrep "Cleared directory .init" actual &&
 +      rmdir init example2
 +'
 +
 +test_expect_success 'submodule deinit fails when submodule has a .git directory even when forced' '
 +      git submodule update --init &&
 +      (
 +              cd init &&
 +              rm .git &&
 +              cp -R ../.git/modules/example .git &&
 +              GIT_WORK_TREE=. git config --unset core.worktree
 +      ) &&
 +      test_must_fail git submodule deinit init &&
 +      test_must_fail git submodule deinit -f init &&
 +      test -d init/.git &&
 +      test -n "$(git config --get-regexp "submodule\.example\.")"
 +'
 +
  test_done
diff --combined t/test-lib-functions.sh
index fac9234d3c688ed588da6844163c5d0e712ba3ab,a8e57f05c1efb2e5302709296fb4169a0fc86c78..8828ff78f184a451fb43709771cc39bf17186cfb
@@@ -139,12 -139,12 +139,12 @@@ test_pause () 
        fi
  }
  
 -# Call test_commit with the arguments "<message> [<file> [<contents>]]"
 +# Call test_commit with the arguments "<message> [<file> [<contents> [<tag>]]]"
  #
  # This will commit a file with the given contents and the given commit
 -# message.  It will also add a tag with <message> as name.
 +# message, and tag the resulting commit with the given tag name.
  #
 -# Both <file> and <contents> default to <message>.
 +# <file>, <contents>, and <tag> all default to <message>.
  
  test_commit () {
        notick= &&
                test_tick
        fi &&
        git commit $signoff -m "$1" &&
 -      git tag "$1"
 +      git tag "${4:-$1}"
  }
  
  # Call test_merge with the arguments "<message> <commit>", where <commit>
@@@ -540,9 -540,6 +540,9 @@@ test_must_fail () 
        elif test $exit_code = 127; then
                echo >&2 "test_must_fail: command not found: $*"
                return 1
 +      elif test $exit_code = 126; then
 +              echo >&2 "test_must_fail: valgrind error: $*"
 +              return 1
        fi
        return 0
  }
@@@ -609,6 -606,18 +609,18 @@@ test_cmp() 
        $GIT_TEST_CMP "$@"
  }
  
+ # Check if the file expected to be empty is indeed empty, and barfs
+ # otherwise.
+ test_must_be_empty () {
+       if test -s "$1"
+       then
+               echo "'$1' is not empty, it contains:"
+               cat "$1"
+               return 1
+       fi
+ }
  # Tests that its two parameters refer to the same revision
  test_cmp_rev () {
        git rev-parse --verify "$1" >expect.rev &&
@@@ -679,20 -688,3 +691,20 @@@ test_create_repo () 
                mv .git/hooks .git/hooks-disabled
        ) || exit
  }
 +
 +# This function helps on symlink challenged file systems when it is not
 +# important that the file system entry is a symbolic link.
 +# Use test_ln_s_add instead of "ln -s x y && git add y" to add a
 +# symbolic link entry y to the index.
 +
 +test_ln_s_add () {
 +      if test_have_prereq SYMLINKS
 +      then
 +              ln -s "$1" "$2" &&
 +              git update-index --add "$2"
 +      else
 +              printf '%s' "$1" >"$2" &&
 +              ln_s_obj=$(git hash-object -w "$2") &&
 +              git update-index --add --cacheinfo 120000 $ln_s_obj "$2"
 +      fi
 +}