Add test helpers for unstaged/uncommitted changes

In order to better test detection of unstaged and uncommitted
changes, add base test methods to create changes and not stage or
commit them, ensuring they can result in an unstaged diff or staged
but uncommitted edits. To ensure that these work, use them within
the simple change creation method to perform the actual file edit.

Change-Id: Ib698d0057a404f073490d1683a8eef8d0c143122
This commit is contained in:
Jeremy Stanley 2021-02-24 20:22:05 +00:00
parent c1b1e6cbfe
commit e8d5404320

View File

@ -313,13 +313,25 @@ class BaseGitReviewTestCase(testtools.TestCase, GerritHelpers):
utils.run_cmd(gerrit_sh, 'start')
self.addCleanup(utils.run_cmd, gerrit_sh, 'stop')
def _unstaged_change(self, change_text, file_=None):
"""Helper method to create small changes and not stage them."""
if file_ is None:
file_ = self._dir('test', 'test_file.txt')
utils.write_to_file(file_, ''.encode())
self._run_git('add', file_)
utils.write_to_file(file_, change_text.encode())
def _uncommitted_change(self, change_text, file_=None):
"""Helper method to create small changes and not commit them."""
if file_ is None:
file_ = self._dir('test', 'test_file.txt')
self._unstaged_change(change_text, file_)
self._run_git('add', file_)
def _simple_change(self, change_text, commit_message,
file_=None):
"""Helper method to create small changes and commit them."""
if file_ is None:
file_ = self._dir('test', 'test_file.txt')
utils.write_to_file(file_, change_text.encode())
self._run_git('add', file_)
self._uncommitted_change(change_text, file_)
self._run_git('commit', '-m', commit_message)
def _simple_amend(self, change_text, file_=None):