From e84b7541ce1bb3d5867fd3de48e446c979af4c01 Mon Sep 17 00:00:00 2001 From: "szager@chromium.org" Date: Fri, 15 Jun 2012 21:26:58 +0000 Subject: [PATCH] Add test for git-svn with submodule/merge layout. Review URL: https://chromiumcodereview.appspot.com/10543151 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@142479 0039d316-1c4b-4281-b951-d872f2087c98 --- git_cl.py | 2 +- tests/abandon.sh | 4 ++ tests/basic.sh | 4 ++ tests/git_cl_test.py | 2 +- tests/hooks.sh | 4 ++ tests/owners.sh | 4 ++ tests/patch.sh | 4 ++ tests/post-dcommit-hook-test.sh | 4 ++ tests/push-basic.sh | 4 ++ tests/push-from-logs.sh | 4 ++ tests/rename.sh | 4 ++ tests/save-description-on-failure.sh | 4 ++ tests/submit-from-new-dir.sh | 4 ++ tests/submodule-merge-test.sh | 58 +++++++++++++++++++++++++++ tests/test-lib.sh | 28 ++++++++++++- tests/upload-local-tracking-branch.sh | 4 ++ tests/upload-stale.sh | 4 ++ tests/upstream.sh | 4 ++ 18 files changed, 143 insertions(+), 3 deletions(-) create mode 100755 tests/submodule-merge-test.sh diff --git a/git_cl.py b/git_cl.py index 6f4d1b976a..5bd6d1be4d 100755 --- a/git_cl.py +++ b/git_cl.py @@ -1145,7 +1145,7 @@ def IsSubmoduleMergeCommit(ref): # When submodules are added to the repo, we expect there to be a single # non-git-svn merge commit at remote HEAD with a signature comment. pattern = '^SVN changes up to revision [0-9]*$' - cmd = ['rev-list', '--merges', '--grep="%s"' % pattern, '%s^!' % ref] + cmd = ['rev-list', '--merges', '--grep=%s' % pattern, '%s^!' % ref] return RunGit(cmd) != '' diff --git a/tests/abandon.sh b/tests/abandon.sh index 85c49ca301..c4bba75e1f 100755 --- a/tests/abandon.sh +++ b/tests/abandon.sh @@ -1,5 +1,9 @@ #!/bin/bash +# Copyright (c) 2012 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + # Check that abandoning a branch also abandons its issue. set -e diff --git a/tests/basic.sh b/tests/basic.sh index 9412f80b21..e22e2151d9 100755 --- a/tests/basic.sh +++ b/tests/basic.sh @@ -1,5 +1,9 @@ #!/bin/bash +# Copyright (c) 2012 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + set -e . ./test-lib.sh diff --git a/tests/git_cl_test.py b/tests/git_cl_test.py index fe4d54db1b..7e9014084d 100755 --- a/tests/git_cl_test.py +++ b/tests/git_cl_test.py @@ -148,7 +148,7 @@ class TestGitCl(TestCase): ((['git', 'config', 'branch.working.merge'],), 'refs/heads/master'), ((['git', 'config', 'branch.working.remote'],), 'origin'), ((['git', 'rev-list', '--merges', - '--grep="^SVN changes up to revision [0-9]*$"', + '--grep=^SVN changes up to revision [0-9]*$', 'refs/remotes/origin/master^!'],), ''), ((['git', 'update-index', '--refresh', '-q'],), ''), ((['git', 'diff-index', 'HEAD'],), ''), diff --git a/tests/hooks.sh b/tests/hooks.sh index 93d6bb432b..d890ce6e5a 100755 --- a/tests/hooks.sh +++ b/tests/hooks.sh @@ -1,5 +1,9 @@ #!/bin/bash +# Copyright (c) 2012 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + # Tests the "preupload and predcommit hooks" functionality, which lets you run # hooks by installing a script into .git/hooks/pre-cl-* first. diff --git a/tests/owners.sh b/tests/owners.sh index 766abcc262..4a4fc63624 100755 --- a/tests/owners.sh +++ b/tests/owners.sh @@ -1,5 +1,9 @@ #!/bin/bash +# Copyright (c) 2012 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + set -e . ./test-lib.sh diff --git a/tests/patch.sh b/tests/patch.sh index b494b442eb..2de361e938 100755 --- a/tests/patch.sh +++ b/tests/patch.sh @@ -1,5 +1,9 @@ #!/bin/bash +# Copyright (c) 2012 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + set -e . ./test-lib.sh diff --git a/tests/post-dcommit-hook-test.sh b/tests/post-dcommit-hook-test.sh index e5d1a17c6d..a047fc1a03 100755 --- a/tests/post-dcommit-hook-test.sh +++ b/tests/post-dcommit-hook-test.sh @@ -1,5 +1,9 @@ #!/bin/bash +# Copyright (c) 2012 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + set -e . ./test-lib.sh diff --git a/tests/push-basic.sh b/tests/push-basic.sh index 9a19cf3526..b378854cdd 100755 --- a/tests/push-basic.sh +++ b/tests/push-basic.sh @@ -1,5 +1,9 @@ #!/bin/bash +# Copyright (c) 2012 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + set -e . ./test-lib.sh diff --git a/tests/push-from-logs.sh b/tests/push-from-logs.sh index 1a1f3d0969..1b6ade7ff9 100755 --- a/tests/push-from-logs.sh +++ b/tests/push-from-logs.sh @@ -1,5 +1,9 @@ #!/bin/bash +# Copyright (c) 2012 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + set -e . ./test-lib.sh diff --git a/tests/rename.sh b/tests/rename.sh index 2f56ddef74..87ac72916d 100755 --- a/tests/rename.sh +++ b/tests/rename.sh @@ -1,5 +1,9 @@ #!/bin/bash +# Copyright (c) 2012 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + # Renaming a file should show up as a rename in the review. set -e diff --git a/tests/save-description-on-failure.sh b/tests/save-description-on-failure.sh index 684b63d0c1..82599eb9b8 100755 --- a/tests/save-description-on-failure.sh +++ b/tests/save-description-on-failure.sh @@ -1,5 +1,9 @@ #!/bin/bash +# Copyright (c) 2012 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + # We should save a change's description when an upload fails. set -e diff --git a/tests/submit-from-new-dir.sh b/tests/submit-from-new-dir.sh index 7ed85f31f3..c1dd89b4ce 100755 --- a/tests/submit-from-new-dir.sh +++ b/tests/submit-from-new-dir.sh @@ -1,5 +1,9 @@ #!/bin/bash +# Copyright (c) 2012 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + # Check that we're able to submit from a directory that doesn't exist on the # trunk. This tests for a previous bug where we ended up with an invalid CWD # after switching to the merge branch. diff --git a/tests/submodule-merge-test.sh b/tests/submodule-merge-test.sh new file mode 100755 index 0000000000..31186ae85d --- /dev/null +++ b/tests/submodule-merge-test.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +# Copyright (c) 2012 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +set -e + +. ./test-lib.sh + +setup_initsvn +setup_gitsvn_submodule + +( + set -e + prev_svn_revision=`svn info file://$PWD/svnrepo | grep ^Revision | \ + sed s/^.*:// | xargs` + cd git-svn-submodule + git config rietveld.server localhost:1 + git checkout -q --track -b work + echo "some work done" >> test + git add test; git commit -q -m "work \ +TBR=foo" + + git_diff=`git diff HEAD^ | sed -n '/^@@/,$p' | xargs` + + test_expect_success "dcommitted code" \ + "$GIT_CL dcommit -f --bypass-hooks -m 'dcommit'" + + cd .. + + next_svn_revision=`svn info file://$PWD/svnrepo | grep ^Revision | \ + sed s/^.*:// | xargs` + + test_expect_success "svn got new revision" \ + "test $next_svn_revision = `expr $prev_svn_revision + 1`" + + svn_diff=`svn diff -c $next_svn_revision file://$PWD/svnrepo | \ + sed -n '/^@@/,$p' | xargs` + + test_expect_success "svn diff is correct" \ + "test \"$git_diff\" = \"$svn_diff\"" + + cd git-svn-submodule + git svn fetch + last_svn_rev=`git show refs/remotes/trunk | grep git-svn-id: | \ + grep -o trunk@[0-9]* | xargs` + + test_expect_success "git svn fetch gets new svn revision" \ + "test $last_svn_rev = trunk@$next_svn_revision" +) +SUCCESS=$? + +#cleanup + +if [ $SUCCESS == 0 ]; then + echo PASS +fi diff --git a/tests/test-lib.sh b/tests/test-lib.sh index a66ce37091..fc3874e15f 100755 --- a/tests/test-lib.sh +++ b/tests/test-lib.sh @@ -1,5 +1,9 @@ #!/bin/bash +# Copyright (c) 2012 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + # Abort on error. set -e @@ -46,6 +50,28 @@ setup_gitsvn() { git svn -q clone -s $REPO_URL git-svn >/dev/null 2>&1 } +# Set up a git-svn checkout of the repo and apply merge commits +# (like the submodule repo layout). +setup_gitsvn_submodule() { + echo "Setting up test remote git-svn-submodule repo..." + rm -rf git-svn-submodule + git svn -q clone -s $REPO_URL git-svn-submodule >/dev/null 2>&1 + svn_revision=`svn info file://$PWD/svnrepo | grep ^Revision | \ + sed s/^.*:// | xargs` + ( + cd git-svn-submodule + echo 'merge-file line 1' > merge-file + git add merge-file; git commit -q -m 'First non-svn commit on master' + git checkout -q refs/remotes/trunk + git merge -q --no-commit --no-ff refs/heads/master >/dev/null 2>&1 + echo 'merge-edit-file line 1' > merge-edit-file + git add merge-edit-file + git commit -q -m "SVN changes up to revision $svn_revision" + git update-ref refs/heads/master HEAD + git checkout master + ) +} + # Set up a git repo that has a few commits to master. setup_initgit() { echo "Setting up test upstream git repo..." @@ -74,7 +100,7 @@ setup_gitgit() { } cleanup() { - rm -rf gitrepo svnrepo svn git-git git-svn + rm -rf gitrepo svnrepo svn git-git git-svn git-svn-submodule } # Usage: test_expect_success "description of test" "test code". diff --git a/tests/upload-local-tracking-branch.sh b/tests/upload-local-tracking-branch.sh index db226ebcba..dcdf149e9c 100755 --- a/tests/upload-local-tracking-branch.sh +++ b/tests/upload-local-tracking-branch.sh @@ -1,5 +1,9 @@ #!/bin/bash +# Copyright (c) 2012 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + set -e . ./test-lib.sh diff --git a/tests/upload-stale.sh b/tests/upload-stale.sh index 87c1cb0395..85a11d2c7b 100755 --- a/tests/upload-stale.sh +++ b/tests/upload-stale.sh @@ -1,5 +1,9 @@ #!/bin/bash +# Copyright (c) 2012 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + set -e . ./test-lib.sh diff --git a/tests/upstream.sh b/tests/upstream.sh index b2f8c93022..0e2ce80b06 100755 --- a/tests/upstream.sh +++ b/tests/upstream.sh @@ -1,5 +1,9 @@ #!/bin/bash +# Copyright (c) 2012 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + # Check guessing the svn upstream branch. set -e