From 60d02ccc18408e54ace8692532fcc73d4035b3c2 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 6 Jul 2006 00:14:16 -0700 Subject: git-svn: migrate out of contrib Allow NO_SVN_TESTS to be defined to skip git-svn tests. These tests are time-consuming due to SVN being slow, and even more so if SVN Perl libraries are not available. Signed-off-by: Eric Wong Signed-off-by: Junio C Hamano --- t/Makefile | 10 ++ t/lib-git-svn.sh | 43 +++++++ t/t9100-git-svn-basic.sh | 234 ++++++++++++++++++++++++++++++++++++++ t/t9101-git-svn-props.sh | 126 ++++++++++++++++++++ t/t9102-git-svn-deep-rmdir.sh | 29 +++++ t/t9103-git-svn-graft-branches.sh | 63 ++++++++++ t/t9104-git-svn-follow-parent.sh | 44 +++++++ t/t9105-git-svn-commit-diff.sh | 41 +++++++ 8 files changed, 590 insertions(+) create mode 100644 t/lib-git-svn.sh create mode 100755 t/t9100-git-svn-basic.sh create mode 100755 t/t9101-git-svn-props.sh create mode 100755 t/t9102-git-svn-deep-rmdir.sh create mode 100755 t/t9103-git-svn-graft-branches.sh create mode 100755 t/t9104-git-svn-follow-parent.sh create mode 100755 t/t9105-git-svn-commit-diff.sh (limited to 't') diff --git a/t/Makefile b/t/Makefile index 632c55f6d..89835093f 100644 --- a/t/Makefile +++ b/t/Makefile @@ -11,6 +11,7 @@ TAR ?= $(TAR) SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH)) T = $(wildcard t[0-9][0-9][0-9][0-9]-*.sh) +TSVN = $(wildcard t91[0-9][0-9]-*.sh) ifdef NO_PYTHON GIT_TEST_OPTS += --no-python @@ -24,6 +25,15 @@ $(T): clean: rm -fr trash +# we can test NO_OPTIMIZE_COMMITS independently of LC_ALL +full-svn-test: + $(MAKE) $(TSVN) GIT_SVN_NO_LIB=1 GIT_SVN_NO_OPTIMIZE_COMMITS=1 LC_ALL=C + $(MAKE) $(TSVN) GIT_SVN_NO_LIB=0 GIT_SVN_NO_OPTIMIZE_COMMITS=1 LC_ALL=C + $(MAKE) $(TSVN) GIT_SVN_NO_LIB=1 GIT_SVN_NO_OPTIMIZE_COMMITS=0 \ + LC_ALL=en_US.UTF-8 + $(MAKE) $(TSVN) GIT_SVN_NO_LIB=0 GIT_SVN_NO_OPTIMIZE_COMMITS=0 \ + LC_ALL=en_US.UTF-8 + .PHONY: $(T) clean .NOTPARALLEL: diff --git a/t/lib-git-svn.sh b/t/lib-git-svn.sh new file mode 100644 index 000000000..450fee899 --- /dev/null +++ b/t/lib-git-svn.sh @@ -0,0 +1,43 @@ +. ./test-lib.sh + +if test -n "$NO_SVN_TESTS" +then + test_expect_success 'skipping git-svn tests, NO_SVN_TESTS defined' : + test_done + exit +fi + +GIT_DIR=$PWD/.git +GIT_SVN_DIR=$GIT_DIR/svn/git-svn +SVN_TREE=$GIT_SVN_DIR/svn-tree + +svnadmin >/dev/null 2>&1 +if test $? != 1 +then + test_expect_success 'skipping git-svn tests, svnadmin not found' : + test_done + exit +fi + +svn >/dev/null 2>&1 +if test $? != 1 +then + test_expect_success 'skipping git-svn tests, svn not found' : + test_done + exit +fi + +svnrepo=$PWD/svnrepo + +set -e + +if svnadmin create --help | grep fs-type >/dev/null +then + svnadmin create --fs-type fsfs "$svnrepo" +else + svnadmin create "$svnrepo" +fi + +svnrepo="file://$svnrepo/test-git-svn" + + diff --git a/t/t9100-git-svn-basic.sh b/t/t9100-git-svn-basic.sh new file mode 100755 index 000000000..bf1d6381d --- /dev/null +++ b/t/t9100-git-svn-basic.sh @@ -0,0 +1,234 @@ +#!/bin/sh +# +# Copyright (c) 2006 Eric Wong +# + +test_description='git-svn basic tests' +GIT_SVN_LC_ALL=$LC_ALL + +case "$LC_ALL" in +*.UTF-8) + have_utf8=t + ;; +*) + have_utf8= + ;; +esac + +. ./lib-git-svn.sh + +echo 'define NO_SVN_TESTS to skip git-svn tests' + +mkdir import +cd import + +echo foo > foo +if test -z "$NO_SYMLINK" +then + ln -s foo foo.link +fi +mkdir -p dir/a/b/c/d/e +echo 'deep dir' > dir/a/b/c/d/e/file +mkdir -p bar +echo 'zzz' > bar/zzz +echo '#!/bin/sh' > exec.sh +chmod +x exec.sh +svn import -m 'import for git-svn' . "$svnrepo" >/dev/null + +cd .. +rm -rf import + +test_expect_success \ + 'initialize git-svn' \ + "git-svn init $svnrepo" + +test_expect_success \ + 'import an SVN revision into git' \ + 'git-svn fetch' + +test_expect_success "checkout from svn" "svn co $svnrepo $SVN_TREE" + +name='try a deep --rmdir with a commit' +git checkout -f -b mybranch remotes/git-svn +mv dir/a/b/c/d/e/file dir/file +cp dir/file file +git update-index --add --remove dir/a/b/c/d/e/file dir/file file +git commit -m "$name" + +test_expect_success "$name" \ + "git-svn commit --find-copies-harder --rmdir remotes/git-svn..mybranch && + svn up $SVN_TREE && + test -d $SVN_TREE/dir && test ! -d $SVN_TREE/dir/a" + + +name='detect node change from file to directory #1' +mkdir dir/new_file +mv dir/file dir/new_file/file +mv dir/new_file dir/file +git update-index --remove dir/file +git update-index --add dir/file/file +git commit -m "$name" + +test_expect_failure "$name" \ + 'git-svn commit --find-copies-harder --rmdir remotes/git-svn..mybranch' \ + || true + + +name='detect node change from directory to file #1' +rm -rf dir $GIT_DIR/index +git checkout -f -b mybranch2 remotes/git-svn +mv bar/zzz zzz +rm -rf bar +mv zzz bar +git update-index --remove -- bar/zzz +git update-index --add -- bar +git commit -m "$name" + +test_expect_failure "$name" \ + 'git-svn commit --find-copies-harder --rmdir remotes/git-svn..mybranch2' \ + || true + + +name='detect node change from file to directory #2' +rm -f $GIT_DIR/index +git checkout -f -b mybranch3 remotes/git-svn +rm bar/zzz +git-update-index --remove bar/zzz +mkdir bar/zzz +echo yyy > bar/zzz/yyy +git-update-index --add bar/zzz/yyy +git commit -m "$name" + +test_expect_failure "$name" \ + 'git-svn commit --find-copies-harder --rmdir remotes/git-svn..mybranch3' \ + || true + + +name='detect node change from directory to file #2' +rm -f $GIT_DIR/index +git checkout -f -b mybranch4 remotes/git-svn +rm -rf dir +git update-index --remove -- dir/file +touch dir +echo asdf > dir +git update-index --add -- dir +git commit -m "$name" + +test_expect_failure "$name" \ + 'git-svn commit --find-copies-harder --rmdir remotes/git-svn..mybranch4' \ + || true + + +name='remove executable bit from a file' +rm -f $GIT_DIR/index +git checkout -f -b mybranch5 remotes/git-svn +chmod -x exec.sh +git update-index exec.sh +git commit -m "$name" + +test_expect_success "$name" \ + "git-svn commit --find-copies-harder --rmdir remotes/git-svn..mybranch5 && + svn up $SVN_TREE && + test ! -x $SVN_TREE/exec.sh" + + +name='add executable bit back file' +chmod +x exec.sh +git update-index exec.sh +git commit -m "$name" + +test_expect_success "$name" \ + "git-svn commit --find-copies-harder --rmdir remotes/git-svn..mybranch5 && + svn up $SVN_TREE && + test -x $SVN_TREE/exec.sh" + + + +if test -z "$NO_SYMLINK" +then + name='executable file becomes a symlink to bar/zzz (file)' + rm exec.sh + ln -s bar/zzz exec.sh + git update-index exec.sh + git commit -m "$name" + + test_expect_success "$name" \ + "git-svn commit --find-copies-harder --rmdir remotes/git-svn..mybranch5 && + svn up $SVN_TREE && + test -L $SVN_TREE/exec.sh" + + name='new symlink is added to a file that was also just made executable' + chmod +x bar/zzz + ln -s bar/zzz exec-2.sh + git update-index --add bar/zzz exec-2.sh + git commit -m "$name" + + test_expect_success "$name" \ + "git-svn commit --find-copies-harder --rmdir remotes/git-svn..mybranch5 && + svn up $SVN_TREE && + test -x $SVN_TREE/bar/zzz && + test -L $SVN_TREE/exec-2.sh" + + name='modify a symlink to become a file' + git help > help || true + rm exec-2.sh + cp help exec-2.sh + git update-index exec-2.sh + git commit -m "$name" + + test_expect_success "$name" \ + "git-svn commit --find-copies-harder --rmdir remotes/git-svn..mybranch5 && + svn up $SVN_TREE && + test -f $SVN_TREE/exec-2.sh && + test ! -L $SVN_TREE/exec-2.sh && + diff -u help $SVN_TREE/exec-2.sh" +fi + + +if test "$have_utf8" = t +then + name="commit with UTF-8 message: locale: $GIT_SVN_LC_ALL" + echo '# hello' >> exec-2.sh + git update-index exec-2.sh + git commit -m 'éï∏' + export LC_ALL="$GIT_SVN_LC_ALL" + test_expect_success "$name" "git-svn commit HEAD" + unset LC_ALL +else + echo "UTF-8 locale not set, test skipped ($GIT_SVN_LC_ALL)" +fi + +name='test fetch functionality (svn => git) with alternate GIT_SVN_ID' +GIT_SVN_ID=alt +export GIT_SVN_ID +test_expect_success "$name" \ + "git-svn init $svnrepo && git-svn fetch && + git-rev-list --pretty=raw remotes/git-svn | grep ^tree | uniq > a && + git-rev-list --pretty=raw remotes/alt | grep ^tree | uniq > b && + diff -u a b" + +if test -n "$NO_SYMLINK" +then + test_done + exit 0 +fi + +name='check imported tree checksums expected tree checksums' +rm -f expected +if test "$have_utf8" = t +then + echo tree f735671b89a7eb30cab1d8597de35bd4271ab813 > expected +fi +cat >> expected <<\EOF +tree 4b9af72bb861eaed053854ec502cf7df72618f0f +tree 031b8d557afc6fea52894eaebb45bec52f1ba6d1 +tree 0b094cbff17168f24c302e297f55bfac65eb8bd3 +tree d667270a1f7b109f5eb3aaea21ede14b56bfdd6e +tree 56a30b966619b863674f5978696f4a3594f2fca9 +tree d667270a1f7b109f5eb3aaea21ede14b56bfdd6e +tree 8f51f74cf0163afc9ad68a4b1537288c4558b5a4 +EOF +test_expect_success "$name" "diff -u a expected" + +test_done + diff --git a/t/t9101-git-svn-props.sh b/t/t9101-git-svn-props.sh new file mode 100755 index 000000000..a5a235f10 --- /dev/null +++ b/t/t9101-git-svn-props.sh @@ -0,0 +1,126 @@ +#!/bin/sh +# +# Copyright (c) 2006 Eric Wong +# + +test_description='git-svn property tests' +. ./lib-git-svn.sh + +mkdir import + +a_crlf= +a_lf= +a_cr= +a_ne_crlf= +a_ne_lf= +a_ne_cr= +a_empty= +a_empty_lf= +a_empty_cr= +a_empty_crlf= + +cd import + cat >> kw.c <<\EOF +/* Somebody prematurely put a keyword into this file */ +/* $Id$ */ +EOF + + printf "Hello\r\nWorld\r\n" > crlf + a_crlf=`git-hash-object -w crlf` + printf "Hello\rWorld\r" > cr + a_cr=`git-hash-object -w cr` + printf "Hello\nWorld\n" > lf + a_lf=`git-hash-object -w lf` + + printf "Hello\r\nWorld" > ne_crlf + a_ne_crlf=`git-hash-object -w ne_crlf` + printf "Hello\nWorld" > ne_lf + a_ne_lf=`git-hash-object -w ne_lf` + printf "Hello\rWorld" > ne_cr + a_ne_cr=`git-hash-object -w ne_cr` + + touch empty + a_empty=`git-hash-object -w empty` + printf "\n" > empty_lf + a_empty_lf=`git-hash-object -w empty_lf` + printf "\r" > empty_cr + a_empty_cr=`git-hash-object -w empty_cr` + printf "\r\n" > empty_crlf + a_empty_crlf=`git-hash-object -w empty_crlf` + + svn import -m 'import for git-svn' . "$svnrepo" >/dev/null +cd .. + +rm -rf import +test_expect_success 'checkout working copy from svn' "svn co $svnrepo test_wc" +test_expect_success 'setup some commits to svn' \ + 'cd test_wc && + echo Greetings >> kw.c && + svn commit -m "Not yet an Id" && + svn up && + echo Hello world >> kw.c && + svn commit -m "Modified file, but still not yet an Id" && + svn up && + svn propset svn:keywords Id kw.c && + svn commit -m "Propset Id" && + svn up && + cd ..' + +test_expect_success 'initialize git-svn' "git-svn init $svnrepo" +test_expect_success 'fetch revisions from svn' 'git-svn fetch' + +name='test svn:keywords ignoring' +test_expect_success "$name" \ + 'git checkout -b mybranch remotes/git-svn && + echo Hi again >> kw.c && + git commit -a -m "test keywoards ignoring" && + git-svn commit remotes/git-svn..mybranch && + git pull . remotes/git-svn' + +expect='/* $Id$ */' +got="`sed -ne 2p kw.c`" +test_expect_success 'raw $Id$ found in kw.c' "test '$expect' = '$got'" + +test_expect_success "propset CR on crlf files" \ + 'cd test_wc && + svn propset svn:eol-style CR empty && + svn propset svn:eol-style CR crlf && + svn propset svn:eol-style CR ne_crlf && + svn commit -m "propset CR on crlf files" && + svn up && + cd ..' + +test_expect_success 'fetch and pull latest from svn and checkout a new wc' \ + "git-svn fetch && + git pull . remotes/git-svn && + svn co $svnrepo new_wc" + +for i in crlf ne_crlf lf ne_lf cr ne_cr empty_cr empty_lf empty empty_crlf +do + test_expect_success "Comparing $i" "cmp $i new_wc/$i" +done + + +cd test_wc + printf '$Id$\rHello\rWorld\r' > cr + printf '$Id$\rHello\rWorld' > ne_cr + a_cr=`printf '$Id$\r\nHello\r\nWorld\r\n' | git-hash-object --stdin` + a_ne_cr=`printf '$Id$\r\nHello\r\nWorld' | git-hash-object --stdin` + test_expect_success 'Set CRLF on cr files' \ + 'svn propset svn:eol-style CRLF cr && + svn propset svn:eol-style CRLF ne_cr && + svn propset svn:keywords Id cr && + svn propset svn:keywords Id ne_cr && + svn commit -m "propset CRLF on cr files" && + svn up' +cd .. +test_expect_success 'fetch and pull latest from svn' \ + 'git-svn fetch && git pull . remotes/git-svn' + +b_cr="`git-hash-object cr`" +b_ne_cr="`git-hash-object ne_cr`" + +test_expect_success 'CRLF + $Id$' "test '$a_cr' = '$b_cr'" +test_expect_success 'CRLF + $Id$ (no newline)' "test '$a_ne_cr' = '$b_ne_cr'" + +test_done diff --git a/t/t9102-git-svn-deep-rmdir.sh b/t/t9102-git-svn-deep-rmdir.sh new file mode 100755 index 000000000..d693d183c --- /dev/null +++ b/t/t9102-git-svn-deep-rmdir.sh @@ -0,0 +1,29 @@ +test_description='git-svn rmdir' +. ./lib-git-svn.sh + +test_expect_success 'initialize repo' " + mkdir import && + cd import && + mkdir -p deeply/nested/directory/number/1 && + mkdir -p deeply/nested/directory/number/2 && + echo foo > deeply/nested/directory/number/1/file && + echo foo > deeply/nested/directory/number/2/another && + svn import -m 'import for git-svn' . $svnrepo && + cd .. + " + +test_expect_success 'mirror via git-svn' " + git-svn init $svnrepo && + git-svn fetch && + git checkout -f -b test-rmdir remotes/git-svn + " + +test_expect_success 'Try a commit on rmdir' " + git rm -f deeply/nested/directory/number/2/another && + git commit -a -m 'remove another' && + git-svn commit --rmdir HEAD && + svn ls -R $svnrepo | grep ^deeply/nested/directory/number/1 + " + + +test_done diff --git a/t/t9103-git-svn-graft-branches.sh b/t/t9103-git-svn-graft-branches.sh new file mode 100755 index 000000000..cc62d4ece --- /dev/null +++ b/t/t9103-git-svn-graft-branches.sh @@ -0,0 +1,63 @@ +test_description='git-svn graft-branches' +. ./lib-git-svn.sh + +test_expect_success 'initialize repo' " + mkdir import && + cd import && + mkdir -p trunk branches tags && + echo hello > trunk/readme && + svn import -m 'import for git-svn' . $svnrepo && + cd .. && + svn cp -m 'tag a' $svnrepo/trunk $svnrepo/tags/a && + svn cp -m 'branch a' $svnrepo/trunk $svnrepo/branches/a && + svn co $svnrepo wc && + cd wc && + echo feedme >> branches/a/readme && + svn commit -m hungry && + svn up && + cd trunk && + svn merge -r3:4 $svnrepo/branches/a && + svn commit -m 'merge with a' && + cd ../.. && + svn log -v $svnrepo && + git-svn init -i trunk $svnrepo/trunk && + git-svn init -i a $svnrepo/branches/a && + git-svn init -i tags/a $svnrepo/tags/a && + git-svn fetch -i tags/a && + git-svn fetch -i a && + git-svn fetch -i trunk + " + +r1=`git-rev-list remotes/trunk | tail -n1` +r2=`git-rev-list remotes/tags/a | tail -n1` +r3=`git-rev-list remotes/a | tail -n1` +r4=`git-rev-list remotes/a | head -n1` +r5=`git-rev-list remotes/trunk | head -n1` + +test_expect_success 'test graft-branches regexes and copies' " + test -n "$r1" && + test -n "$r2" && + test -n "$r3" && + test -n "$r4" && + test -n "$r5" && + git-svn graft-branches && + grep '^$r2 $r1' $GIT_DIR/info/grafts && + grep '^$r3 $r1' $GIT_DIR/info/grafts && + grep '^$r5 ' $GIT_DIR/info/grafts | grep '$r4' | grep '$r1' + " + +test_debug 'gitk --all & sleep 1' + +test_expect_success 'test graft-branches with tree-joins' " + rm $GIT_DIR/info/grafts && + git-svn graft-branches --no-default-regex --no-graft-copy -B && + grep '^$r3 ' $GIT_DIR/info/grafts | grep '$r1' | grep '$r2' && + grep '^$r2 $r1' $GIT_DIR/info/grafts && + grep '^$r5 ' $GIT_DIR/info/grafts | grep '$r1' | grep '$r4' + " + +# the result of this is kinda funky, we have a strange history and +# this is just a test :) +test_debug 'gitk --all &' + +test_done diff --git a/t/t9104-git-svn-follow-parent.sh b/t/t9104-git-svn-follow-parent.sh new file mode 100755 index 000000000..01488ff78 --- /dev/null +++ b/t/t9104-git-svn-follow-parent.sh @@ -0,0 +1,44 @@ +#!/bin/sh +# +# Copyright (c) 2006 Eric Wong +# + +test_description='git-svn --follow-parent fetching' +. ./lib-git-svn.sh + +if test -n "$GIT_SVN_NO_LIB" && test "$GIT_SVN_NO_LIB" -ne 0 +then + echo 'Skipping: --follow-parent needs SVN libraries' + test_done + exit 0 +fi + +test_expect_success 'initialize repo' " + mkdir import && + cd import && + mkdir -p trunk && + echo hello > trunk/readme && + svn import -m 'initial' . $svnrepo && + cd .. && + svn co $svnrepo wc && + cd wc && + echo world >> trunk/readme && + svn commit -m 'another commit' && + svn up && + svn mv -m 'rename to thunk' trunk thunk && + svn up && + echo goodbye >> thunk/readme && + svn commit -m 'bye now' && + cd .. + " + +test_expect_success 'init and fetch --follow-parent a moved directory' " + git-svn init -i thunk $svnrepo/thunk && + git-svn fetch --follow-parent -i thunk && + git-rev-parse --verify refs/remotes/trunk && + test '$?' -eq '0' + " + +test_debug 'gitk --all &' + +test_done diff --git a/t/t9105-git-svn-commit-diff.sh b/t/t9105-git-svn-commit-diff.sh new file mode 100755 index 000000000..f994b72f8 --- /dev/null +++ b/t/t9105-git-svn-commit-diff.sh @@ -0,0 +1,41 @@ +#!/bin/sh +# +# Copyright (c) 2006 Eric Wong +test_description='git-svn commit-diff' +. ./lib-git-svn.sh + +if test -n "$GIT_SVN_NO_LIB" && test "$GIT_SVN_NO_LIB" -ne 0 +then + echo 'Skipping: commit-diff needs SVN libraries' + test_done + exit 0 +fi + +test_expect_success 'initialize repo' " + mkdir import && + cd import && + echo hello > readme && + svn import -m 'initial' . $svnrepo && + cd .. && + echo hello > readme && + git update-index --add readme && + git commit -a -m 'initial' && + echo world >> readme && + git commit -a -m 'another' + " + +head=`git rev-parse --verify HEAD^0` +prev=`git rev-parse --verify HEAD^1` + +# the internals of the commit-diff command are the same as the regular +# commit, so only a basic test of functionality is needed since we've +# already tested commit extensively elsewhere + +test_expect_success 'test the commit-diff command' " + test -n '$prev' && test -n '$head' && + git-svn commit-diff '$prev' '$head' '$svnrepo' && + svn co $svnrepo wc && + cmp readme wc/readme + " + +test_done -- cgit v1.2.1