diff options
Diffstat (limited to 'WebKitTools/Scripts/webkitpy/common/checkout')
4 files changed, 154 insertions, 181 deletions
diff --git a/WebKitTools/Scripts/webkitpy/common/checkout/api.py b/WebKitTools/Scripts/webkitpy/common/checkout/api.py index a5ac939..ca28e32 100644 --- a/WebKitTools/Scripts/webkitpy/common/checkout/api.py +++ b/WebKitTools/Scripts/webkitpy/common/checkout/api.py @@ -83,16 +83,16 @@ class Checkout(object): def bug_id_for_revision(self, revision): return self.commit_info_for_revision(revision).bug_id() - def modified_changelogs(self, git_commit, squash): + def modified_changelogs(self, git_commit): # SCM returns paths relative to scm.checkout_root # Callers (especially those using the ChangeLog class) may # expect absolute paths, so this method returns absolute paths. - changed_files = self._scm.changed_files(git_commit, squash) + changed_files = self._scm.changed_files(git_commit) absolute_paths = [os.path.join(self._scm.checkout_root, path) for path in changed_files] return [path for path in absolute_paths if self._is_path_to_changelog(path)] - def commit_message_for_this_commit(self, git_commit, squash): - changelog_paths = self.modified_changelogs(git_commit, squash) + def commit_message_for_this_commit(self, git_commit): + changelog_paths = self.modified_changelogs(git_commit) if not len(changelog_paths): raise ScriptError(message="Found no modified ChangeLogs, cannot create a commit message.\n" "All changes require a ChangeLog. See:\n" @@ -109,9 +109,9 @@ class Checkout(object): # FIXME: We should sort and label the ChangeLog messages like commit-log-editor does. return CommitMessage("".join(changelog_messages).splitlines()) - def bug_id_for_this_commit(self, git_commit, squash): + def bug_id_for_this_commit(self, git_commit): try: - return parse_bug_id(self.commit_message_for_this_commit(git_commit, squash).message()) + return parse_bug_id(self.commit_message_for_this_commit(git_commit).message()) except ScriptError, e: pass # We might not have ChangeLogs. @@ -131,7 +131,7 @@ class Checkout(object): # We revert the ChangeLogs because removing lines from a ChangeLog # doesn't make sense. ChangeLogs are append only. - changelog_paths = self.modified_changelogs(git_commit=None, squash=False) + changelog_paths = self.modified_changelogs(git_commit=None) if len(changelog_paths): self._scm.revert_files(changelog_paths) diff --git a/WebKitTools/Scripts/webkitpy/common/checkout/api_unittest.py b/WebKitTools/Scripts/webkitpy/common/checkout/api_unittest.py index 1436379..fdfd879 100644 --- a/WebKitTools/Scripts/webkitpy/common/checkout/api_unittest.py +++ b/WebKitTools/Scripts/webkitpy/common/checkout/api_unittest.py @@ -114,11 +114,11 @@ class CommitMessageForThisCommitTest(unittest.TestCase): # ChangeLog is difficult to mock at current. def test_commit_message_for_this_commit(self): checkout = Checkout(None) - checkout.modified_changelogs = lambda git_commit, squash: ["ChangeLog1", "ChangeLog2"] + checkout.modified_changelogs = lambda git_commit: ["ChangeLog1", "ChangeLog2"] output = OutputCapture() expected_stderr = "Parsing ChangeLog: ChangeLog1\nParsing ChangeLog: ChangeLog2\n" commit_message = output.assert_outputs(self, checkout.commit_message_for_this_commit, - kwargs={"git_commit": None, "squash": False}, expected_stderr=expected_stderr) + kwargs={"git_commit": None}, expected_stderr=expected_stderr) self.assertEqual(commit_message.message(), self.expected_commit_message) @@ -163,13 +163,13 @@ class CheckoutTest(unittest.TestCase): def test_bug_id_for_this_commit(self): scm = Mock() checkout = Checkout(scm) - checkout.commit_message_for_this_commit = lambda git_commit, squash: CommitMessage(ChangeLogEntry(_changelog1entry1).contents().splitlines()) - self.assertEqual(checkout.bug_id_for_this_commit(git_commit=None, squash=False), 36629) + checkout.commit_message_for_this_commit = lambda git_commit: CommitMessage(ChangeLogEntry(_changelog1entry1).contents().splitlines()) + self.assertEqual(checkout.bug_id_for_this_commit(git_commit=None), 36629) def test_modified_changelogs(self): scm = Mock() scm.checkout_root = "/foo/bar" - scm.changed_files = lambda git_commit, squash: ["file1", "ChangeLog", "relative/path/ChangeLog"] + scm.changed_files = lambda git_commit: ["file1", "ChangeLog", "relative/path/ChangeLog"] checkout = Checkout(scm) expected_changlogs = ["/foo/bar/ChangeLog", "/foo/bar/relative/path/ChangeLog"] - self.assertEqual(checkout.modified_changelogs(git_commit=None, squash=False), expected_changlogs) + self.assertEqual(checkout.modified_changelogs(git_commit=None), expected_changlogs) diff --git a/WebKitTools/Scripts/webkitpy/common/checkout/scm.py b/WebKitTools/Scripts/webkitpy/common/checkout/scm.py index d7c621c..569558a 100644 --- a/WebKitTools/Scripts/webkitpy/common/checkout/scm.py +++ b/WebKitTools/Scripts/webkitpy/common/checkout/scm.py @@ -35,7 +35,6 @@ import sys import shutil from webkitpy.common.system.executive import Executive, run_command, ScriptError -from webkitpy.common.system.user import User from webkitpy.common.system.deprecated_logging import error, log @@ -94,6 +93,17 @@ def commit_error_handler(error): Executive.default_error_handler(error) +class AuthenticationError(Exception): + def __init__(self, server_host): + self.server_host = server_host + + +class AmbiguousCommitError(Exception): + def __init__(self, num_local_commits, working_directory_is_clean): + self.num_local_commits = num_local_commits + self.working_directory_is_clean = working_directory_is_clean + + # SCM methods are expected to return paths relative to self.checkout_root. class SCM: def __init__(self, cwd): @@ -198,7 +208,7 @@ class SCM: def delete(self, path): self._subclass_must_implement() - def changed_files(self, git_commit=None, squash=None): + def changed_files(self, git_commit=None): self._subclass_must_implement() def changed_files_for_revision(self): @@ -213,7 +223,7 @@ class SCM: def display_name(self): self._subclass_must_implement() - def create_patch(self, git_commit=None, squash=None): + def create_patch(self, git_commit=None): self._subclass_must_implement() def committer_email_for_revision(self, revision): @@ -237,10 +247,7 @@ class SCM: def revert_files(self, file_paths): self._subclass_must_implement() - def should_squash(self, squash): - self._subclass_must_implement() - - def commit_with_message(self, message, username=None, git_commit=None, squash=None): + def commit_with_message(self, message, username=None, git_commit=None, force_squash=False): self._subclass_must_implement() def svn_commit_log(self, svn_revision): @@ -377,7 +384,7 @@ class SVN(SCM): parent, base = os.path.split(os.path.abspath(path)) return self.run(["svn", "delete", "--force", base], cwd=parent) - def changed_files(self, git_commit=None, squash=None): + def changed_files(self, git_commit=None): return self.run_status_and_extract_filenames(self.status_command(), self._status_regexp("ACDMR")) def changed_files_for_revision(self, revision): @@ -403,7 +410,7 @@ class SVN(SCM): return "svn" # FIXME: This method should be on Checkout. - def create_patch(self, git_commit=None, squash=None): + def create_patch(self, git_commit=None): """Returns a byte array (str()) representing the patch file. Patch files are effectively binary since they may contain files of multiple different encodings.""" @@ -477,22 +484,19 @@ class SVN(SCM): # FIXME: This should probably use cwd=self.checkout_root. self.run(['svn', 'revert'] + file_paths) - def should_squash(self, squash): - # SVN doesn't support the concept of squashing. - return False - - def commit_with_message(self, message, username=None, git_commit=None, squash=None): - # squash and git-commit are not used by SVN. + def commit_with_message(self, message, username=None, git_commit=None, force_squash=False): + # git-commit and force are not used by SVN. if self.dryrun: # Return a string which looks like a commit so that things which parse this output will succeed. return "Dry run, no commit.\nCommitted revision 0." + svn_commit_args = ["svn", "commit"] + if not username and not self.has_authorization_for_realm(): - username = User.prompt("%s login: " % self.svn_server_host, repeat=5) - if not username: - raise Exception("You need to specify the username on %s to perform the commit as." % self.svn_server_host) + raise AuthenticationError(self.svn_server_host) if username: svn_commit_args.extend(["--username", username]) + svn_commit_args.extend(["-m", message]) # FIXME: Should this use cwd=self.checkout_root? return self.run(svn_commit_args, error_handler=commit_error_handler) @@ -584,24 +588,25 @@ class Git(SCM): def delete(self, path): return self.run(["git", "rm", "-f", path]) - def _merge_base(self, git_commit, squash): + def _assert_synced(self): + if len(run_command(['git', 'rev-list', '--max-count=1', self.remote_branch_ref(), '^HEAD'])): + raise ScriptError(message="Not fully merged/rebased to %s. This branch needs to be synced first." % self.remote_branch_ref()) + + def merge_base(self, git_commit): if git_commit: - # FIXME: Calling code should turn commit ranges into a list of commit IDs - # and then treat each commit separately. + # Special-case HEAD.. to mean working-copy changes only. + if git_commit.upper() == 'HEAD..': + return 'HEAD' + if '..' not in git_commit: git_commit = git_commit + "^.." + git_commit return git_commit - if self.should_squash(squash): - return self.remote_merge_base() - - # FIXME: Non-squash behavior should match commit_with_message. It raises an error - # if there are working copy changes and --squash or --no-squash wasn't passed in. - # If --no-squash, then it should proceed with each local commit as a separate patch. - return 'HEAD' + self._assert_synced() + return self.remote_merge_base() - def changed_files(self, git_commit=None, squash=None): - status_command = ['git', 'diff', '-r', '--name-status', '-C', '-M', "--no-ext-diff", "--full-index", self._merge_base(git_commit, squash)] + def changed_files(self, git_commit=None): + status_command = ['git', 'diff', '-r', '--name-status', '-C', '-M', "--no-ext-diff", "--full-index", self.merge_base(git_commit)] return self.run_status_and_extract_filenames(status_command, self._status_regexp("ADM")) def _changes_files_for_commit(self, git_commit): @@ -633,12 +638,12 @@ class Git(SCM): def display_name(self): return "git" - def create_patch(self, git_commit=None, squash=None): + def create_patch(self, git_commit=None): """Returns a byte array (str()) representing the patch file. Patch files are effectively binary since they may contain files of multiple different encodings.""" # FIXME: This should probably use cwd=self.checkout_root - return self.run(['git', 'diff', '--binary', "--no-ext-diff", "--full-index", "-M", self._merge_base(git_commit, squash)], decode_output=False) + return self.run(['git', 'diff', '--binary', "--no-ext-diff", "--full-index", "-M", self.merge_base(git_commit)], decode_output=False) @classmethod def git_commit_from_svn_revision(cls, revision): @@ -679,63 +684,41 @@ class Git(SCM): def revert_files(self, file_paths): self.run(['git', 'checkout', 'HEAD'] + file_paths) - def _get_squash_error_message(self, num_local_commits): - working_directory_message = "" if self.working_directory_is_clean() else " and working copy changes" - return ("""There are %s local commits%s. Do one of the following: - 1) Use --squash or --no-squash - 2) git config webkit-patch.squash true/false - """ % (num_local_commits, working_directory_message)) - - def should_squash(self, squash): - if squash is None: - config_squash = Git.read_git_config('webkit-patch.squash') - if (config_squash and config_squash is not ""): - squash = config_squash.lower() == "true" - else: - # Only raise an error if there are actually multiple commits to squash. - num_local_commits = len(self.local_commits()) - if num_local_commits > 1 or (num_local_commits > 0 and not self.working_directory_is_clean()): - raise ScriptError(message=self._get_squash_error_message(num_local_commits)) - - if squash and self._remote_branch_has_extra_commits(): - raise ScriptError(message="Cannot use --squash when HEAD is not fully merged/rebased to %s. " - "This branch needs to be synced first." % self.remote_branch_ref()) + def _assert_can_squash(self, working_directory_is_clean): + squash = Git.read_git_config('webkit-patch.commit_should_always_squash') + should_squash = squash and squash.lower() == "true" - return squash + if not should_squash: + # Only warn if there are actually multiple commits to squash. + num_local_commits = len(self.local_commits()) + if num_local_commits > 1 or (num_local_commits > 0 and not working_directory_is_clean): + raise AmbiguousCommitError(num_local_commits, working_directory_is_clean) - def _remote_branch_has_extra_commits(self): - return len(run_command(['git', 'rev-list', '--max-count=1', self.remote_branch_ref(), '^HEAD'])) - - def commit_with_message(self, message, username=None, git_commit=None, squash=None): + def commit_with_message(self, message, username=None, git_commit=None, force_squash=False): # Username is ignored during Git commits. + working_directory_is_clean = self.working_directory_is_clean() + if git_commit: + # Special-case HEAD.. to mean working-copy changes only. + if git_commit.upper() == 'HEAD..': + if working_directory_is_clean: + raise ScriptError(message="The working copy is not modified. --git-commit=HEAD.. only commits working copy changes.") + self.commit_locally_with_message(message) + return self._commit_on_branch(message, 'HEAD') + # Need working directory changes to be committed so we can checkout the merge branch. - if not self.working_directory_is_clean(): + if not working_directory_is_clean: # FIXME: webkit-patch land will modify the ChangeLogs to correct the reviewer. # That will modify the working-copy and cause us to hit this error. - # The ChangeLog modification could be made to modify the existing local commit? + # The ChangeLog modification could be made to modify the existing local commit. raise ScriptError(message="Working copy is modified. Cannot commit individual git_commits.") return self._commit_on_branch(message, git_commit) - squash = self.should_squash(squash) - if squash: - self.run(['git', 'reset', '--soft', self.remote_branch_ref()]) - self.commit_locally_with_message(message) - elif not self.working_directory_is_clean(): - if not len(self.local_commits()): - # There are only working copy changes. Assume they should be committed. - self.commit_locally_with_message(message) - elif squash is None: - # The user didn't explicitly say to squash or not squash. There are local commits - # and working copy changes. Not clear what the user wants. - raise ScriptError(message="""There are local commits and working copy changes. Do one of the following: -1) Commit/revert working copy changes. -2) Use --squash or --no-squash -3) git config webkit-patch.squash true/false -""") - - # FIXME: This will commit all local commits, each with it's own message. We should restructure - # so that each local commit has the appropriate commit message based off it's ChangeLogs. + if not force_squash: + self._assert_can_squash(working_directory_is_clean) + self._assert_synced() + self.run(['git', 'reset', '--soft', self.remote_branch_ref()]) + self.commit_locally_with_message(message) return self.push_local_commits_to_server() def _commit_on_branch(self, message, git_commit): diff --git a/WebKitTools/Scripts/webkitpy/common/checkout/scm_unittest.py b/WebKitTools/Scripts/webkitpy/common/checkout/scm_unittest.py index eaa3b46..852f838 100644 --- a/WebKitTools/Scripts/webkitpy/common/checkout/scm_unittest.py +++ b/WebKitTools/Scripts/webkitpy/common/checkout/scm_unittest.py @@ -44,7 +44,7 @@ import shutil from datetime import date from webkitpy.common.checkout.api import Checkout -from webkitpy.common.checkout.scm import detect_scm_system, SCM, SVN, CheckoutNeedsUpdate, commit_error_handler +from webkitpy.common.checkout.scm import detect_scm_system, SCM, SVN, CheckoutNeedsUpdate, commit_error_handler, AuthenticationError, AmbiguousCommitError from webkitpy.common.config.committers import Committer # FIXME: This should not be needed from webkitpy.common.net.bugzilla import Attachment # FIXME: This should not be needed from webkitpy.common.system.executive import Executive, run_command, ScriptError @@ -597,6 +597,10 @@ Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== def test_commit_with_username(self): self._shared_test_commit_with_message("dbates@webkit.org") + def test_commit_without_authorization(self): + self.scm.has_authorization_for_realm = lambda: False + self.assertRaises(AuthenticationError, self._shared_test_commit_with_message) + def test_has_authorization_for_realm(self): scm = detect_scm_system(self.svn_checkout_path) fake_home_dir = tempfile.mkdtemp(suffix="fake_home_dir") @@ -867,24 +871,14 @@ class GitSVNTest(SCMTest): def test_commit_text_parsing(self): write_into_file_at_path('test_file', 'more test content') - self.scm.commit_locally_with_message("another test commit") commit_text = self.scm.commit_with_message("another test commit") self.assertEqual(self.scm.svn_revision_from_commit_text(commit_text), '6') self.scm.dryrun = True write_into_file_at_path('test_file', 'still more test content') - self.scm.commit_locally_with_message("yet another test commit") commit_text = self.scm.commit_with_message("yet another test commit") self.assertEqual(self.scm.svn_revision_from_commit_text(commit_text), '0') - def _one_local_commit_plus_working_copy_changes(self): - write_into_file_at_path('test_file_commit1', 'more test content') - run_command(['git', 'add', 'test_file_commit1']) - self.scm.commit_locally_with_message("another test commit") - - write_into_file_at_path('test_file_commit2', 'still more test content') - run_command(['git', 'add', 'test_file_commit2']) - def test_commit_with_message_working_copy_only(self): write_into_file_at_path('test_file_commit1', 'more test content') run_command(['git', 'add', 'test_file_commit1']) @@ -895,21 +889,18 @@ class GitSVNTest(SCMTest): svn_log = run_command(['git', 'svn', 'log', '--limit=1', '--verbose']) self.assertTrue(re.search(r'test_file_commit1', svn_log)) - def test_commit_with_message_squashed(self): - self._one_local_commit_plus_working_copy_changes() - scm = detect_scm_system(self.git_checkout_path) - commit_text = scm.commit_with_message("yet another test commit", squash=True) - - self.assertEqual(scm.svn_revision_from_commit_text(commit_text), '6') - svn_log = run_command(['git', 'svn', 'log', '--limit=1', '--verbose']) - self.assertTrue(re.search(r'test_file_commit2', svn_log)) - self.assertTrue(re.search(r'test_file_commit1', svn_log)) - - def _two_local_commits(self): + def _one_local_commit(self): write_into_file_at_path('test_file_commit1', 'more test content') run_command(['git', 'add', 'test_file_commit1']) self.scm.commit_locally_with_message("another test commit") + def _one_local_commit_plus_working_copy_changes(self): + self._one_local_commit() + write_into_file_at_path('test_file_commit2', 'still more test content') + run_command(['git', 'add', 'test_file_commit2']) + + def _two_local_commits(self): + self._one_local_commit() write_into_file_at_path('test_file_commit2', 'still more test content') run_command(['git', 'add', 'test_file_commit2']) self.scm.commit_locally_with_message("yet another test commit") @@ -920,6 +911,17 @@ class GitSVNTest(SCMTest): self.scm.commit_locally_with_message("another test commit") self._two_local_commits() + def test_commit_with_message(self): + self._one_local_commit_plus_working_copy_changes() + scm = detect_scm_system(self.git_checkout_path) + self.assertRaises(AmbiguousCommitError, scm.commit_with_message, "yet another test commit") + commit_text = scm.commit_with_message("yet another test commit", force_squash=True) + + self.assertEqual(scm.svn_revision_from_commit_text(commit_text), '6') + svn_log = run_command(['git', 'svn', 'log', '--limit=1', '--verbose']) + self.assertTrue(re.search(r'test_file_commit2', svn_log)) + self.assertTrue(re.search(r'test_file_commit1', svn_log)) + def test_commit_with_message_git_commit(self): self._two_local_commits() @@ -943,51 +945,68 @@ class GitSVNTest(SCMTest): self.assertTrue(re.search(r'test_file_commit1', svn_log)) self.assertTrue(re.search(r'test_file_commit2', svn_log)) - def test_commit_with_message_multiple_local_commits(self): - self._two_local_commits() + def test_changed_files_working_copy_only(self): + self._one_local_commit_plus_working_copy_changes() scm = detect_scm_system(self.git_checkout_path) - self.assertRaises(ScriptError, scm.commit_with_message, ["another test commit"]) + commit_text = scm.commit_with_message("another test commit", git_commit="HEAD..") + self.assertFalse(re.search(r'test_file_commit1', svn_log)) + self.assertTrue(re.search(r'test_file_commit2', svn_log)) + + def test_commit_with_message_only_local_commit(self): + self._one_local_commit() + scm = detect_scm_system(self.git_checkout_path) + commit_text = scm.commit_with_message("another test commit") + svn_log = run_command(['git', 'svn', 'log', '--limit=1', '--verbose']) + self.assertTrue(re.search(r'test_file_commit1', svn_log)) def test_commit_with_message_multiple_local_commits_and_working_copy(self): self._two_local_commits() write_into_file_at_path('test_file_commit1', 'working copy change') scm = detect_scm_system(self.git_checkout_path) - self.assertRaises(ScriptError, scm.commit_with_message, ["another test commit"]) + + self.assertRaises(AmbiguousCommitError, scm.commit_with_message, "another test commit") + commit_text = scm.commit_with_message("another test commit", force_squash=True) + + self.assertEqual(scm.svn_revision_from_commit_text(commit_text), '6') + svn_log = run_command(['git', 'svn', 'log', '--limit=1', '--verbose']) + self.assertTrue(re.search(r'test_file_commit2', svn_log)) + self.assertTrue(re.search(r'test_file_commit1', svn_log)) def test_commit_with_message_git_commit_and_working_copy(self): self._two_local_commits() write_into_file_at_path('test_file_commit1', 'working copy change') scm = detect_scm_system(self.git_checkout_path) - self.assertRaises(ScriptError, scm.commit_with_message, ["another test commit", 'git_commit="HEAD^"']) + self.assertRaises(ScriptError, scm.commit_with_message, "another test commit", git_commit="HEAD^") - def test_commit_with_message_multiple_local_commits_no_squash(self): + def test_commit_with_message_multiple_local_commits_always_squash(self): self._two_local_commits() scm = detect_scm_system(self.git_checkout_path) - commit_text = scm.commit_with_message("yet another test commit", squash=False) + scm._assert_can_squash = lambda working_directory_is_clean: True + commit_text = scm.commit_with_message("yet another test commit") self.assertEqual(scm.svn_revision_from_commit_text(commit_text), '6') svn_log = run_command(['git', 'svn', 'log', '--limit=1', '--verbose']) self.assertTrue(re.search(r'test_file_commit2', svn_log)) - self.assertFalse(re.search(r'test_file_commit1', svn_log)) - - svn_log = run_command(['git', 'svn', 'log', '--limit=2', '--verbose']) self.assertTrue(re.search(r'test_file_commit1', svn_log)) - def test_commit_with_message_multiple_local_commits_squash(self): + def test_commit_with_message_multiple_local_commits(self): self._two_local_commits() scm = detect_scm_system(self.git_checkout_path) - commit_text = scm.commit_with_message("yet another test commit", squash=True) + self.assertRaises(AmbiguousCommitError, scm.commit_with_message, "yet another test commit") + commit_text = scm.commit_with_message("yet another test commit", force_squash=True) + self.assertEqual(scm.svn_revision_from_commit_text(commit_text), '6') svn_log = run_command(['git', 'svn', 'log', '--limit=1', '--verbose']) self.assertTrue(re.search(r'test_file_commit2', svn_log)) self.assertTrue(re.search(r'test_file_commit1', svn_log)) - def test_commit_with_message_not_synced_squash(self): + def test_commit_with_message_not_synced(self): run_command(['git', 'checkout', '-b', 'my-branch', 'trunk~3']) self._two_local_commits() scm = detect_scm_system(self.git_checkout_path) - self.assertRaises(ScriptError, scm.commit_with_message, "another test commit", squash=True) + self.assertRaises(AmbiguousCommitError, scm.commit_with_message, "another test commit") + self.assertRaises(ScriptError, scm.commit_with_message, "another test commit", force_squash=True) def test_remote_branch_ref(self): self.assertEqual(self.scm.remote_branch_ref(), 'refs/remotes/trunk') @@ -1004,26 +1023,16 @@ class GitSVNTest(SCMTest): def test_create_patch_local_plus_working_copy(self): self._one_local_commit_plus_working_copy_changes() scm = detect_scm_system(self.git_checkout_path) - self.assertRaises(ScriptError, scm.create_patch) - - def test_create_patch_multiple_local_commits(self): - self._two_local_commits() - scm = detect_scm_system(self.git_checkout_path) - self.assertRaises(ScriptError, scm.create_patch) - - def test_create_patch_squashed(self): - self._one_local_commit_plus_working_copy_changes() - scm = detect_scm_system(self.git_checkout_path) - patch = scm.create_patch(squash=True) - self.assertTrue(re.search(r'test_file_commit2', patch)) + patch = scm.create_patch() self.assertTrue(re.search(r'test_file_commit1', patch)) + self.assertTrue(re.search(r'test_file_commit2', patch)) - def test_create_patch_not_squashed(self): + def test_create_patch(self): self._one_local_commit_plus_working_copy_changes() scm = detect_scm_system(self.git_checkout_path) - patch = scm.create_patch(squash=False) + patch = scm.create_patch() self.assertTrue(re.search(r'test_file_commit2', patch)) - self.assertFalse(re.search(r'test_file_commit1', patch)) + self.assertTrue(re.search(r'test_file_commit1', patch)) def test_create_patch_git_commit(self): self._two_local_commits() @@ -1040,26 +1049,25 @@ class GitSVNTest(SCMTest): self.assertTrue(re.search(r'test_file_commit2', patch)) self.assertTrue(re.search(r'test_file_commit1', patch)) - def test_create_patch_multiple_local_commits_no_squash(self): - self._two_local_commits() + def test_create_patch_working_copy_only(self): + self._one_local_commit_plus_working_copy_changes() scm = detect_scm_system(self.git_checkout_path) - patch = scm.create_patch(squash=False) - # FIXME: It's weird that with squash=False, create_patch/changed_files ignores local commits, - # but commit_with_message commits them. - self.assertTrue(patch == "") + patch = scm.create_patch(git_commit="HEAD..") + self.assertFalse(re.search(r'test_file_commit1', patch)) + self.assertTrue(re.search(r'test_file_commit2', patch)) - def test_create_patch_multiple_local_commits_squash(self): + def test_create_patch_multiple_local_commits(self): self._two_local_commits() scm = detect_scm_system(self.git_checkout_path) - patch = scm.create_patch(squash=True) + patch = scm.create_patch() self.assertTrue(re.search(r'test_file_commit2', patch)) self.assertTrue(re.search(r'test_file_commit1', patch)) - def test_create_patch_not_synced_squash(self): + def test_create_patch_not_synced(self): run_command(['git', 'checkout', '-b', 'my-branch', 'trunk~3']) self._two_local_commits() scm = detect_scm_system(self.git_checkout_path) - self.assertRaises(ScriptError, scm.create_patch, squash=True) + self.assertRaises(ScriptError, scm.create_patch) def test_create_binary_patch(self): # Create a git binary patch and check the contents. @@ -1090,26 +1098,9 @@ class GitSVNTest(SCMTest): def test_changed_files_local_plus_working_copy(self): self._one_local_commit_plus_working_copy_changes() scm = detect_scm_system(self.git_checkout_path) - self.assertRaises(ScriptError, scm.changed_files) - - def test_changed_files_multiple_local_commits(self): - self._two_local_commits() - scm = detect_scm_system(self.git_checkout_path) - self.assertRaises(ScriptError, scm.changed_files) - - def test_changed_files_squashed(self): - self._one_local_commit_plus_working_copy_changes() - scm = detect_scm_system(self.git_checkout_path) - files = scm.changed_files(squash=True) - self.assertTrue('test_file_commit2' in files) + files = scm.changed_files() self.assertTrue('test_file_commit1' in files) - - def test_changed_files_not_squashed(self): - self._one_local_commit_plus_working_copy_changes() - scm = detect_scm_system(self.git_checkout_path) - files = scm.changed_files(squash=False) self.assertTrue('test_file_commit2' in files) - self.assertFalse('test_file_commit1' in files) def test_changed_files_git_commit(self): self._two_local_commits() @@ -1126,26 +1117,25 @@ class GitSVNTest(SCMTest): self.assertTrue('test_file_commit1' in files) self.assertTrue('test_file_commit2' in files) - def test_changed_files_multiple_local_commits_no_squash(self): - self._two_local_commits() + def test_changed_files_working_copy_only(self): + self._one_local_commit_plus_working_copy_changes() scm = detect_scm_system(self.git_checkout_path) - files = scm.changed_files(squash=False) - # FIXME: It's weird that with squash=False, create_patch/changed_files ignores local commits, - # but commit_with_message commits them. - self.assertTrue(len(files) == 0) + files = scm.changed_files(git_commit="HEAD..") + self.assertFalse('test_file_commit1' in files) + self.assertTrue('test_file_commit2' in files) - def test_changed_files_multiple_local_commits_squash(self): + def test_changed_files_multiple_local_commits(self): self._two_local_commits() scm = detect_scm_system(self.git_checkout_path) - files = scm.changed_files(squash=True) + files = scm.changed_files() self.assertTrue('test_file_commit2' in files) self.assertTrue('test_file_commit1' in files) - def test_changed_files_not_synced_squash(self): + def test_changed_files_not_synced(self): run_command(['git', 'checkout', '-b', 'my-branch', 'trunk~3']) self._two_local_commits() scm = detect_scm_system(self.git_checkout_path) - self.assertRaises(ScriptError, scm.changed_files, squash=True) + self.assertRaises(ScriptError, scm.changed_files) def test_changed_files(self): self._shared_test_changed_files() |