mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
Track expected git errors in logs
Sometimes it is expected that a GitCommand executed in repo fails. In such cases indicate in trace logs that the error was expected. Bug: b/293344017 Change-Id: If137fae9ef9769258246f5b4494e070345db4a71 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/387714 Commit-Queue: Jason Chang <jasonnc@google.com> Reviewed-by: Gavin Mak <gavinmak@google.com> Tested-by: Jason Chang <jasonnc@google.com>
This commit is contained in:
parent
b5644160b7
commit
87058c6ca5
@ -286,6 +286,7 @@ class GitCommand(object):
|
|||||||
objdir=None,
|
objdir=None,
|
||||||
verify_command=False,
|
verify_command=False,
|
||||||
add_event_log=True,
|
add_event_log=True,
|
||||||
|
log_as_error=True,
|
||||||
):
|
):
|
||||||
if project:
|
if project:
|
||||||
if not cwd:
|
if not cwd:
|
||||||
@ -362,6 +363,7 @@ class GitCommand(object):
|
|||||||
"ReturnCode": str(e.git_rc)
|
"ReturnCode": str(e.git_rc)
|
||||||
if e.git_rc is not None
|
if e.git_rc is not None
|
||||||
else None,
|
else None,
|
||||||
|
"IsError": log_as_error,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
event_log.ErrorEvent(
|
event_log.ErrorEvent(
|
||||||
|
31
project.py
31
project.py
@ -205,7 +205,9 @@ class ReviewableBranch(object):
|
|||||||
"--",
|
"--",
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
self._commit_cache = self.project.bare_git.rev_list(*args)
|
self._commit_cache = self.project.bare_git.rev_list(
|
||||||
|
*args, log_as_error=self.base_exists
|
||||||
|
)
|
||||||
except GitError:
|
except GitError:
|
||||||
# We weren't able to probe the commits for this branch. Was it
|
# We weren't able to probe the commits for this branch. Was it
|
||||||
# tracking a branch that no longer exists? If so, return no
|
# tracking a branch that no longer exists? If so, return no
|
||||||
@ -1593,7 +1595,9 @@ class Project(object):
|
|||||||
# See if we can perform a fast forward merge. This can happen if our
|
# See if we can perform a fast forward merge. This can happen if our
|
||||||
# branch isn't in the exact same state as we last published.
|
# branch isn't in the exact same state as we last published.
|
||||||
try:
|
try:
|
||||||
self.work_git.merge_base("--is-ancestor", HEAD, revid)
|
self.work_git.merge_base(
|
||||||
|
"--is-ancestor", HEAD, revid, log_as_error=False
|
||||||
|
)
|
||||||
# Skip the published logic.
|
# Skip the published logic.
|
||||||
pub = False
|
pub = False
|
||||||
except GitError:
|
except GitError:
|
||||||
@ -2304,15 +2308,26 @@ class Project(object):
|
|||||||
# if revision (sha or tag) is not present then following function
|
# if revision (sha or tag) is not present then following function
|
||||||
# throws an error.
|
# throws an error.
|
||||||
self.bare_git.rev_list(
|
self.bare_git.rev_list(
|
||||||
"-1", "--missing=allow-any", "%s^0" % self.revisionExpr, "--"
|
"-1",
|
||||||
|
"--missing=allow-any",
|
||||||
|
"%s^0" % self.revisionExpr,
|
||||||
|
"--",
|
||||||
|
log_as_error=False,
|
||||||
)
|
)
|
||||||
if self.upstream:
|
if self.upstream:
|
||||||
rev = self.GetRemote().ToLocal(self.upstream)
|
rev = self.GetRemote().ToLocal(self.upstream)
|
||||||
self.bare_git.rev_list(
|
self.bare_git.rev_list(
|
||||||
"-1", "--missing=allow-any", "%s^0" % rev, "--"
|
"-1",
|
||||||
|
"--missing=allow-any",
|
||||||
|
"%s^0" % rev,
|
||||||
|
"--",
|
||||||
|
log_as_error=False,
|
||||||
)
|
)
|
||||||
self.bare_git.merge_base(
|
self.bare_git.merge_base(
|
||||||
"--is-ancestor", self.revisionExpr, rev
|
"--is-ancestor",
|
||||||
|
self.revisionExpr,
|
||||||
|
rev,
|
||||||
|
log_as_error=False,
|
||||||
)
|
)
|
||||||
return True
|
return True
|
||||||
except GitError:
|
except GitError:
|
||||||
@ -3612,7 +3627,7 @@ class Project(object):
|
|||||||
self.update_ref("-d", name, old)
|
self.update_ref("-d", name, old)
|
||||||
self._project.bare_ref.deleted(name)
|
self._project.bare_ref.deleted(name)
|
||||||
|
|
||||||
def rev_list(self, *args, **kw):
|
def rev_list(self, *args, log_as_error=True, **kw):
|
||||||
if "format" in kw:
|
if "format" in kw:
|
||||||
cmdv = ["log", "--pretty=format:%s" % kw["format"]]
|
cmdv = ["log", "--pretty=format:%s" % kw["format"]]
|
||||||
else:
|
else:
|
||||||
@ -3626,6 +3641,7 @@ class Project(object):
|
|||||||
capture_stdout=True,
|
capture_stdout=True,
|
||||||
capture_stderr=True,
|
capture_stderr=True,
|
||||||
verify_command=True,
|
verify_command=True,
|
||||||
|
log_as_error=log_as_error,
|
||||||
)
|
)
|
||||||
p.Wait()
|
p.Wait()
|
||||||
return p.stdout.splitlines()
|
return p.stdout.splitlines()
|
||||||
@ -3653,7 +3669,7 @@ class Project(object):
|
|||||||
"""
|
"""
|
||||||
name = name.replace("_", "-")
|
name = name.replace("_", "-")
|
||||||
|
|
||||||
def runner(*args, **kwargs):
|
def runner(*args, log_as_error=True, **kwargs):
|
||||||
cmdv = []
|
cmdv = []
|
||||||
config = kwargs.pop("config", None)
|
config = kwargs.pop("config", None)
|
||||||
for k in kwargs:
|
for k in kwargs:
|
||||||
@ -3674,6 +3690,7 @@ class Project(object):
|
|||||||
capture_stdout=True,
|
capture_stdout=True,
|
||||||
capture_stderr=True,
|
capture_stderr=True,
|
||||||
verify_command=True,
|
verify_command=True,
|
||||||
|
log_as_error=log_as_error,
|
||||||
)
|
)
|
||||||
p.Wait()
|
p.Wait()
|
||||||
r = p.stdout
|
r = p.stdout
|
||||||
|
Loading…
Reference in New Issue
Block a user