Commit 1bfda8ee authored by Sigurd Schneider's avatar Sigurd Schneider Committed by LUCI CQ

Respect git config cl.date-order in `git cl st`

In the previous commit https://crrev.com/c/2532835 the option
to order branches by date was added. This CL adds a git config
variable cl.date-order than can be set to achive the same effect.

Change-Id: Iaf24c46c5f7b63b1e518c18aedc455808a2dc752
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2992887Reviewed-by: 's avatarJosip Sokcevic <sokcevic@google.com>
Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
parent 7f69c8fe
......@@ -721,6 +721,7 @@ class Settings(object):
self.gerrit_skip_ensure_authenticated = None
self.git_editor = None
self.format_full_by_default = None
self.is_status_commit_order_by_date = None
def _LazyUpdateIfNeeded(self):
"""Updates the settings from a codereview.settings file, if available."""
......@@ -831,6 +832,13 @@ class Settings(object):
self.format_full_by_default = (result == 'true')
return self.format_full_by_default
def IsStatusCommitOrderByDate(self):
if self.is_status_commit_order_by_date is None:
result = (RunGit(['config', '--bool', 'cl.date-order'],
error_ok=True).strip())
self.is_status_commit_order_by_date = (result == 'true')
return self.is_status_commit_order_by_date
def _GetConfig(self, key, default=''):
self._LazyUpdateIfNeeded()
return scm.GIT.GetConfig(self.GetRoot(), key, default)
......@@ -3697,7 +3705,8 @@ def CMDstatus(parser, args):
branch_statuses = {}
alignment = max(5, max(len(FormatBranchName(c.GetBranch())) for c in changes))
if options.date_order:
if options.date_order or settings.IsStatusCommitOrderByDate():
sorted_changes = sorted(changes,
key=lambda c: c.GetCommitDate(),
reverse=True)
......
......@@ -4201,6 +4201,7 @@ class CMDStatusTestCase(CMDTestCaseBase):
@mock.patch('git_cl.RunGit', _mock_run_git)
@mock.patch('git_cl.get_cl_statuses', _mock_get_cl_statuses)
@mock.patch('git_cl.Settings.GetRoot', return_value='')
@mock.patch('git_cl.Settings.IsStatusCommitOrderByDate', return_value=False)
@mock.patch('scm.GIT.GetBranch', return_value='a')
def testStatus(self, *_mocks):
self.assertEqual(0, git_cl.main(['status', '--no-branch-color']))
......@@ -4224,6 +4225,7 @@ class CMDStatusTestCase(CMDTestCaseBase):
@mock.patch('git_cl.RunGit', _mock_run_git)
@mock.patch('git_cl.get_cl_statuses', _mock_get_cl_statuses)
@mock.patch('git_cl.Settings.GetRoot', return_value='')
@mock.patch('git_cl.Settings.IsStatusCommitOrderByDate', return_value=False)
@mock.patch('scm.GIT.GetBranch', return_value='a')
def testStatusByDate(self, *_mocks):
self.assertEqual(
......@@ -4242,6 +4244,30 @@ class CMDStatusTestCase(CMDTestCaseBase):
'Issue description:\n'
'x\n')
@mock.patch('git_cl.Changelist.EnsureAuthenticated')
@mock.patch('git_cl.Changelist.FetchDescription', lambda cl, pretty: 'x')
@mock.patch('git_cl.Changelist.GetIssue', lambda cl: cl.issue)
@mock.patch('git_cl.RunGit', _mock_run_git)
@mock.patch('git_cl.get_cl_statuses', _mock_get_cl_statuses)
@mock.patch('git_cl.Settings.GetRoot', return_value='')
@mock.patch('git_cl.Settings.IsStatusCommitOrderByDate', return_value=True)
@mock.patch('scm.GIT.GetBranch', return_value='a')
def testStatusByDate(self, *_mocks):
self.assertEqual(
0, git_cl.main(['status', '--no-branch-color']))
self.maxDiff = None
self.assertEqual(
sys.stdout.getvalue(), 'Branches associated with reviews:\n'
' f : https://crrev.com/c/106 (open)\n'
' e : https://crrev.com/c/105 (open)\n'
' d : https://crrev.com/c/104 (open)\n'
' c : https://crrev.com/c/103 (open)\n'
' b : https://crrev.com/c/102 (open)\n'
' * a : https://crrev.com/c/101 (open)\n\n'
'Current branch: a\n'
'Issue number: 101 (https://chromium-review.googlesource.com/101)\n'
'Issue description:\n'
'x\n')
class CMDOwnersTestCase(CMDTestCaseBase):
def setUp(self):
......
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