Commit 9450767a authored by Gavin Mak's avatar Gavin Mak Committed by LUCI CQ

Revert "Error out of rebase-update if there are uncommitted changes"

This reverts commit eff810e9.

Reason for revert: breaks workflows for users

Original change's description:
> Error out of rebase-update if there are uncommitted changes
>
> Currently, running rebase-update may lead to missing untracked files.
> This change prints an error instead freezing and thawing local changes.
>
> Bug: 1251047
> Change-Id: Ia5f718ed957dae936d2ead2778760ae0c8d9f9ea
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3171828
> Commit-Queue: Gavin Mak <gavinmak@google.com>
> Reviewed-by: Josip Sokcevic <sokcevic@google.com>

Bug: 1251047
Change-Id: I5b61dc1c7af13ccca6ea80baecff0522291083c9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3191674
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: Gavin Mak <gavinmak@google.com>
parent d2fe58c1
......@@ -256,9 +256,12 @@ def main(args=None):
return_branch, return_workdir = find_return_branch_workdir()
os.chdir(git.run('rev-parse', '--show-toplevel'))
if git.run('status', '--porcelain'):
print('Cannot rebase-update with uncommitted changes.')
return 1
if git.current_branch() == 'HEAD':
if git.run('status', '--porcelain'):
print('Cannot rebase-update with detached head + uncommitted changes.')
return 1
else:
git.freeze() # just in case there are any local changes.
branches_to_rebase = set(opts.branches)
if opts.current:
......@@ -319,6 +322,7 @@ def main(args=None):
# return_branch may not be there any more.
if return_branch in git.branches():
git.run('checkout', return_branch)
git.thaw()
else:
root_branch = git.root()
if return_branch != 'HEAD':
......
......@@ -105,10 +105,6 @@ class GitRebaseUpdateTest(git_test_utils.GitRepoReadWriteTestBase):
self.repo.git('reset', '--hard', self.repo['A'])
with self.repo.open('old_file', 'w') as f:
f.write('old_files we want to keep around')
output, _ = self.repo.capture_stdio(self.reup.main)
self.assertIn('Cannot rebase-update', output)
self.repo.git('add', 'old_file')
self.repo.git_commit('old_file')
self.repo.git('config', 'branch.old_branch.dormant', 'true')
......@@ -125,6 +121,12 @@ class GitRebaseUpdateTest(git_test_utils.GitRepoReadWriteTestBase):
self.assertEqual(self.repo['A'], self.origin['A'])
self.assertEqual(self.repo['E'], self.origin['E'])
with self.repo.open('bob', 'wb') as f:
f.write(b'testing auto-freeze/thaw')
output, _ = self.repo.capture_stdio(self.reup.main)
self.assertIn('Cannot rebase-update', output)
self.repo.run(self.nb.main, ['empty_branch'])
self.repo.run(self.nb.main, ['--upstream-current', 'empty_branch2'])
......@@ -158,6 +160,11 @@ class GitRebaseUpdateTest(git_test_utils.GitRepoReadWriteTestBase):
self.assertIn('foobar up-to-date', output)
self.assertIn('sub_K up-to-date', output)
with self.repo.open('bob') as f:
self.assertEqual(b'testing auto-freeze/thaw', f.read())
self.assertEqual(self.repo.git('status', '--porcelain').stdout, '?? bob\n')
self.repo.git('checkout', 'origin/main')
_, err = self.repo.capture_stdio(self.rp.main, [])
self.assertIn('Must specify new parent somehow', err)
......@@ -186,6 +193,7 @@ class GitRebaseUpdateTest(git_test_utils.GitRepoReadWriteTestBase):
self.assertTrue(self.repo.run(self.gc.in_rebase))
self.repo.git('rebase', '--abort')
self.assertIsNone(self.repo.run(self.gc.thaw))
self.assertSchema("""
A B C D E F G M N O foobar1 foobar2 H I J K L
......@@ -194,6 +202,8 @@ class GitRebaseUpdateTest(git_test_utils.GitRepoReadWriteTestBase):
K sub_K
""")
self.assertEqual(self.repo.git('status', '--porcelain').stdout, '?? bob\n')
branches = self.repo.run(set, self.gc.branches())
self.assertEqual(branches, {'branch_K', 'main', 'sub_K', 'root_A',
'branch_L', 'old_branch', 'foobar',
......@@ -304,6 +314,7 @@ class GitRebaseUpdateTest(git_test_utils.GitRepoReadWriteTestBase):
self.assertIn('could not be cleanly rebased:', output)
self.assertIn(' branch_K', output)
def testTrackTag(self):
self.origin.git('tag', 'lkgr', self.origin['M'])
self.repo.git('tag', 'lkgr', self.repo['D'])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment