summaryrefslogtreecommitdiffstats
path: root/project.py
diff options
context:
space:
mode:
authorJason Chang <jasonnc@google.com>2023-08-08 14:12:53 -0700
committerLUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-08-10 23:46:31 +0000
commit1a3612fe6d347e458a53d7a9e920a91ea502e6ba (patch)
tree02b1a61f1d97e32201ea5fa309bf1f1b6050e929 /project.py
parentf0aeb220def22edfac9838288ad251f86da782c1 (diff)
downloadgit-repo-1a3612fe6d347e458a53d7a9e920a91ea502e6ba.tar.gz
Raise RepoExitError in place of sys.exit
Bug: b/293344017 Change-Id: Icae4932b00e4068cba502a5ab4a0274fd7854d9d Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/382214 Reviewed-by: Gavin Mak <gavinmak@google.com> Tested-by: Jason Chang <jasonnc@google.com> Reviewed-by: Aravind Vasudevan <aravindvasudev@google.com> Commit-Queue: Jason Chang <jasonnc@google.com>
Diffstat (limited to 'project.py')
-rw-r--r--project.py54
1 files changed, 28 insertions, 26 deletions
diff --git a/project.py b/project.py
index c3eb09c9..6e6a605e 100644
--- a/project.py
+++ b/project.py
@@ -1733,8 +1733,7 @@ class Project(object):
1733 cmd.append( 1733 cmd.append(
1734 "refs/changes/%2.2d/%d/%d" % (change_id % 100, change_id, patch_id) 1734 "refs/changes/%2.2d/%d/%d" % (change_id % 100, change_id, patch_id)
1735 ) 1735 )
1736 if GitCommand(self, cmd, bare=True).Wait() != 0: 1736 GitCommand(self, cmd, bare=True, verify_command=True).Wait()
1737 return None
1738 return DownloadedChange( 1737 return DownloadedChange(
1739 self, 1738 self,
1740 self.GetRevisionId(), 1739 self.GetRevisionId(),
@@ -1911,7 +1910,10 @@ class Project(object):
1911 1910
1912 all_refs = self.bare_ref.all 1911 all_refs = self.bare_ref.all
1913 if R_HEADS + name in all_refs: 1912 if R_HEADS + name in all_refs:
1914 return GitCommand(self, ["checkout", "-q", name, "--"]).Wait() == 0 1913 GitCommand(
1914 self, ["checkout", "-q", name, "--"], verify_command=True
1915 ).Wait()
1916 return True
1915 1917
1916 branch = self.GetBranch(name) 1918 branch = self.GetBranch(name)
1917 branch.remote = self.GetRemote() 1919 branch.remote = self.GetRemote()
@@ -1938,15 +1940,13 @@ class Project(object):
1938 branch.Save() 1940 branch.Save()
1939 return True 1941 return True
1940 1942
1941 if ( 1943 GitCommand(
1942 GitCommand( 1944 self,
1943 self, ["checkout", "-q", "-b", branch.name, revid] 1945 ["checkout", "-q", "-b", branch.name, revid],
1944 ).Wait() 1946 verify_command=True,
1945 == 0 1947 ).Wait()
1946 ): 1948 branch.Save()
1947 branch.Save() 1949 return True
1948 return True
1949 return False
1950 1950
1951 def CheckoutBranch(self, name): 1951 def CheckoutBranch(self, name):
1952 """Checkout a local topic branch. 1952 """Checkout a local topic branch.
@@ -1955,8 +1955,8 @@ class Project(object):
1955 name: The name of the branch to checkout. 1955 name: The name of the branch to checkout.
1956 1956
1957 Returns: 1957 Returns:
1958 True if the checkout succeeded; False if it didn't; None if the 1958 True if the checkout succeeded; False if the
1959 branch didn't exist. 1959 branch doesn't exist.
1960 """ 1960 """
1961 rev = R_HEADS + name 1961 rev = R_HEADS + name
1962 head = self.work_git.GetHead() 1962 head = self.work_git.GetHead()
@@ -1969,7 +1969,7 @@ class Project(object):
1969 revid = all_refs[rev] 1969 revid = all_refs[rev]
1970 except KeyError: 1970 except KeyError:
1971 # Branch does not exist in this project. 1971 # Branch does not exist in this project.
1972 return None 1972 return False
1973 1973
1974 if head.startswith(R_HEADS): 1974 if head.startswith(R_HEADS):
1975 try: 1975 try:
@@ -1986,15 +1986,14 @@ class Project(object):
1986 ) 1986 )
1987 return True 1987 return True
1988 1988
1989 return ( 1989 GitCommand(
1990 GitCommand( 1990 self,
1991 self, 1991 ["checkout", name, "--"],
1992 ["checkout", name, "--"], 1992 capture_stdout=True,
1993 capture_stdout=True, 1993 capture_stderr=True,
1994 capture_stderr=True, 1994 verify_command=True,
1995 ).Wait() 1995 ).Wait()
1996 == 0 1996 return True
1997 )
1998 1997
1999 def AbandonBranch(self, name): 1998 def AbandonBranch(self, name):
2000 """Destroy a local topic branch. 1999 """Destroy a local topic branch.
@@ -4458,9 +4457,12 @@ class ManifestProject(MetaProject):
4458 syncbuf.Finish() 4457 syncbuf.Finish()
4459 4458
4460 if is_new or self.CurrentBranch is None: 4459 if is_new or self.CurrentBranch is None:
4461 if not self.StartBranch("default"): 4460 try:
4461 self.StartBranch("default")
4462 except GitError as e:
4463 msg = str(e)
4462 print( 4464 print(
4463 "fatal: cannot create default in manifest", 4465 f"fatal: cannot create default in manifest {msg}",
4464 file=sys.stderr, 4466 file=sys.stderr,
4465 ) 4467 )
4466 return False 4468 return False