git-cl-patch: Return to cherry-pick, but hard reset with --force
This is a partial revert of https://chromium-review.googlesource.com/c/527345/
Turns out more people were confused by the new behavior than
expected, so we're returning to "cherry-pick" being the default,
but supporting the collaboration workflow is important, so we're
adding a warning message and support for "reset --hard" behind a
pre-existing flag.
Bug: 723787
Change-Id: Ib6038a42e3bdcc0db93c1f32d759e9ff0e91a065
Reviewed-on: https://chromium-review.googlesource.com/538137
Commit-Queue: Aaron Gable <agable@chromium.org>
Reviewed-by: Dirk Pranke <dpranke@chromium.org>
Reviewed-by: Andrii Shyshkalov <tandrii@chromium.org>
diff --git a/tests/git_cl_test.py b/tests/git_cl_test.py
index 4ae5f17..ddb4080 100755
--- a/tests/git_cl_test.py
+++ b/tests/git_cl_test.py
@@ -2127,8 +2127,7 @@
self.calls += [
((['git', 'fetch', 'https://chromium.googlesource.com/my/repo',
'refs/changes/56/123456/7'],), ''),
- ((['git', 'merge-base', '--is-ancestor', 'HEAD', 'origin/master'],), ''),
- ((['git', 'reset', '--hard', 'FETCH_HEAD'],), ''),
+ ((['git', 'cherry-pick', 'FETCH_HEAD'],), ''),
((['git', 'config', 'branch.master.gerritissue', '123456'],),
''),
((['git', 'config', 'branch.master.gerritserver',
@@ -2146,7 +2145,6 @@
self.calls += [
((['git', 'fetch', 'https://host.googlesource.com/my/repo',
'refs/changes/56/123456/7'],), ''),
- ((['git', 'merge-base', '--is-ancestor', 'HEAD', 'origin/master'],), ''),
((['git', 'reset', '--hard', 'FETCH_HEAD'],), ''),
((['git', 'config', 'branch.master.gerritissue', '123456'],),
''),
@@ -2157,7 +2155,7 @@
((['git', 'config', 'branch.master.last-upload-hash', 'deadbeef'],), ''),
((['git', 'config', 'branch.master.gerritsquashhash', 'deadbeef'],), ''),
]
- self.assertEqual(git_cl.main(['patch', '--gerrit', '123456']), 0)
+ self.assertEqual(git_cl.main(['patch', '--gerrit', '123456', '--force']), 0)
def test_patch_gerrit_guess_by_url(self):
self._patch_common(
@@ -2167,8 +2165,7 @@
self.calls += [
((['git', 'fetch', 'https://else.googlesource.com/my/repo',
'refs/changes/56/123456/1'],), ''),
- ((['git', 'merge-base', '--is-ancestor', 'HEAD', 'origin/master'],), ''),
- ((['git', 'reset', '--hard', 'FETCH_HEAD'],), ''),
+ ((['git', 'cherry-pick', 'FETCH_HEAD'],), ''),
((['git', 'symbolic-ref', 'HEAD'],), 'master'),
((['git', 'config', 'branch.master.gerritissue', '123456'],),
''),
@@ -2190,8 +2187,7 @@
self.calls += [
((['git', 'fetch', 'https://else.googlesource.com/my/repo',
'refs/changes/56/123456/1'],), ''),
- ((['git', 'merge-base', '--is-ancestor', 'HEAD', 'origin/master'],), ''),
- ((['git', 'reset', '--hard', 'FETCH_HEAD'],), ''),
+ ((['git', 'cherry-pick', 'FETCH_HEAD'],), ''),
((['git', 'symbolic-ref', 'HEAD'],), 'master'),
((['git', 'config', 'branch.master.gerritissue', '123456'],),
''),
@@ -2205,42 +2201,12 @@
self.assertEqual(git_cl.main(
['patch', 'https://else-review.googlesource.com/123456/1']), 0)
- def test_patch_gerrit_local_content(self):
- self._patch_common(default_codereview='gerrit', detect_gerrit_server=True,
- git_short_host='chromium')
- self.calls += [
- ((['git', 'fetch', 'https://chromium.googlesource.com/my/repo',
- 'refs/changes/56/123456/7'],), ''),
- ((['git', 'merge-base', '--is-ancestor', 'HEAD', 'origin/master'],),
- CERR1),
- ((['git', 'merge-base', '--is-ancestor', 'HEAD', 'FETCH_HEAD'],),
- CERR1),
- (('ask_for_data',
- 'It looks like you\'re on a branch with some local commits.\n'
- 'If you apply this patch on top of your local content, you will not be '
- 'able to easily upload further changes based on it.\n'
- 'Would you like to proceed with applying this patch anyway?\n'
- 'Press Enter to confirm, or Ctrl+C to abort'), 'y'),
- ((['git', 'cherry-pick', 'FETCH_HEAD'],), ''),
- ]
- self.assertEqual(git_cl.main(['patch', '123456']), 0)
-
def test_patch_gerrit_conflict(self):
self._patch_common(default_codereview='gerrit', detect_gerrit_server=True,
git_short_host='chromium')
self.calls += [
((['git', 'fetch', 'https://chromium.googlesource.com/my/repo',
'refs/changes/56/123456/7'],), ''),
- ((['git', 'merge-base', '--is-ancestor', 'HEAD', 'origin/master'],),
- CERR1),
- ((['git', 'merge-base', '--is-ancestor', 'HEAD', 'FETCH_HEAD'],),
- CERR1),
- (('ask_for_data',
- 'It looks like you\'re on a branch with some local commits.\n'
- 'If you apply this patch on top of your local content, you will not be '
- 'able to easily upload further changes based on it.\n'
- 'Would you like to proceed with applying this patch anyway?\n'
- 'Press Enter to confirm, or Ctrl+C to abort'), 'y'),
((['git', 'cherry-pick', 'FETCH_HEAD'],), CERR1),
((['DieWithError', 'Command "git cherry-pick FETCH_HEAD" failed.\n'],),
SystemExitMock()),