Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(192)

Unified Diff: tests/git_cl_test.py

Issue 1091283004: Don't clean up after conflict in "git cl patch" (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« git_cl.py ('K') | « git_cl.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/git_cl_test.py
diff --git a/tests/git_cl_test.py b/tests/git_cl_test.py
index 68be49f792cccf455404b6dfe0428cfa4c43e64a..e10371c9f0434dc21e2e772664448efafde93fdf 100755
--- a/tests/git_cl_test.py
+++ b/tests/git_cl_test.py
@@ -109,9 +109,17 @@ class TestGitCl(TestCase):
self.assertTrue(
self.calls,
'@%d Expected: <Missing> Actual: %r' % (self._calls_done, args))
- expected_args, result = self.calls.pop(0)
+ top = self.calls.pop(0)
+ if len(top) == 2:
+ expected_args, result = top
+ exception = None
+ else:
+ expected_args, result, exception = top
Sam Clegg 2015/04/20 23:32:16 nit: Do the raise here and avoid the "exception =
wychen 2015/04/22 00:23:18 Done.
+
# Also logs otherwise it could get caught in a try/finally and be hard to
# diagnose.
+ if exception:
+ raise exception
if expected_args != args:
msg = '@%d Expected: %r Actual: %r' % (
self._calls_done, expected_args, args)
@@ -853,6 +861,44 @@ class TestGitCl(TestCase):
git_cl.GetTargetRef('origin', 'refs/remotes/origin/master',
None, 'prefix/'))
+ def test_patch_when_dirty(self):
+ # Patch when local tree is dirty
+ self.mock(git_common, 'is_dirty_git_tree', lambda x: True)
+ self.assertNotEqual(git_cl.main(['patch', '123456']), 0)
+
+ def test_diff_when_dirty(self):
+ # Do 'git cl diff' when local tree is dirty
+ self.mock(git_common, 'is_dirty_git_tree', lambda x: True)
+ self.assertNotEqual(git_cl.main(['diff']), 0)
+
+ def _patch_common(self):
+ self.mock(git_cl.Changelist, 'GetMostRecentPatchset', lambda x: '60001')
+ self.mock(git_cl.Changelist, 'GetPatchSetDiff', lambda *args: None)
+ self.mock(git_cl.Changelist, 'SetIssue', lambda *args: None)
+ self.mock(git_cl.Changelist, 'SetPatchset', lambda *args: None)
+ self.mock(git_cl, 'IsGitVersionAtLeast', lambda *args: True)
+
+ self.calls = [
+ ((['git', 'config', 'rietveld.autoupdate'],), ''),
+ ((['git', 'config', 'rietveld.server'],), 'codereview.example.com'),
+ ((['git', 'rev-parse', '--show-cdup'],), ''),
+ ((['sed', '-e', 's|^--- a/|--- |; s|^+++ b/|+++ |'],), ''),
+ ]
+
+ def test_patch_successful(self):
+ self._patch_common()
+ self.calls += [
+ ((['git', 'apply', '--index', '-p0', '--3way'],), ''),
+ ((['git', 'commit', '-m', 'patch from issue 123456 at patchset 60001 (http://crrev.com/123456#ps60001)'],), ''),
+ ]
+ self.assertEqual(git_cl.main(['patch', '123456']), 0)
+
+ def test_patch_conflict(self):
+ self._patch_common()
+ self.calls += [
+ ((['git', 'apply', '--index', '-p0', '--3way'],), '', subprocess2.CalledProcessError(1, '', '', '', '')),
+ ]
+ self.assertNotEqual(git_cl.main(['patch', '123456']), 0)
if __name__ == '__main__':
git_cl.logging.basicConfig(
« git_cl.py ('K') | « git_cl.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698