Skip to content
Snippets Groups Projects
Commit 2dd9eb12 authored by Christian Dreher's avatar Christian Dreher
Browse files

feature: Introduce summarize flag to only replace outputs if explicitly...

feature: Introduce summarize flag to only replace outputs if explicitly requested and not change default behaviour.
parent 60642fc1
No related branches found
No related tags found
No related merge requests found
......@@ -21,14 +21,14 @@ class Update(Hook):
default_checkout_ref: Optional[str] = None
submodules: bool = False
def update(self, **kwargs):
def update(self, summarize=False, **kwargs):
if os.path.isdir(os.path.join(self.ctx.path, ".git")):
return self.pull(**kwargs)
return self.pull(summarize=summarize, **kwargs)
else:
console.print(f"Cloning {self.ctx.name} into '{self.ctx.path}' ...")
return self.clone(**kwargs)
return self.clone(summarize=summarize, **kwargs)
def clone(self, **kwargs):
def clone(self, summarize=False, **kwargs):
url = self.ssh_url or self.https_url
args = [f"{url} {self.ctx.path}"]
if self.default_checkout_ref:
......@@ -38,20 +38,27 @@ class Update(Hook):
if self.submodules:
r2 = commands.run("git submodule update --init", cwd=self.ctx.path, **kwargs)
r += "\n" + r2
if summarize:
if 'Cloning into' in r:
return 'Cloned repository.'
return r
def pull(self, **kwargs):
def pull(self, summarize=False, **kwargs):
try:
out = commands.run("git pull --no-edit", cwd=self.ctx.path, **kwargs)
if summarize:
if 'Updating' in out:
return 'Updated repository.'
return out
except error.CommandFailed as e:
out = e.stderr
if 'You are not currently on a branch' in out:
raise RuntimeError('Not on a branch.')
elif 'Your local changes to the following files would be overwritten by merge' in out:
raise RuntimeError('Local changes would be overwritten.')
else:
raise RuntimeError(f"{e}\n{e.stderr}")
if summarize:
if 'You are not currently on a branch' in out:
raise RuntimeError('Not on a branch.')
elif 'Your local changes to the following files would be overwritten by merge' in out:
raise RuntimeError('Local changes would be overwritten.')
raise RuntimeError(f"{e}\n{e.stderr}")
git: Optional[Git] = None
......
......@@ -325,7 +325,7 @@ class Workspace:
color='green'
status='Succeeded'
try:
output = m.update(capture_output=True, quiet=True)
output = m.update(summarize=True, capture_output=True, quiet=True)
except Exception as e:
color='red'
status='Failed'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment