Skip to content

Commit

Permalink
Merge pull request #420 from JrGoodle/branch
Browse files Browse the repository at this point in the history
Fix clowder branch
  • Loading branch information
JrGoodle committed Apr 18, 2020
2 parents 314145d + 2519611 commit 17e025f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 24 deletions.
41 changes: 23 additions & 18 deletions src/clowder/git/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,24 +300,10 @@ def print_branches(self, local=False, remote=False):
:param Optional[bool] remote: Print remote branches
"""

if local and remote:
command = 'git branch -a'
elif local:
command = 'git branch'
elif remote:
command = 'git branch -r'
else:
return

print('FIXME: Implement')
return

# try:
# execute_command(command, self.repo_path, print_output=self._print_output)
# except ClowderError:
# message = colored(' - Failed to print branches', 'red')
# self._print(message)
# self._exit(message)
if local:
self._print_local_branches()
if remote:
self._print_remote_branches()

@not_detached
def pull(self):
Expand Down Expand Up @@ -510,6 +496,25 @@ def _print(self, val):
if self._print_output:
print(val)

def _print_local_branches(self):
"""Print local git branches"""

for branch in self.repo.git.branch().split('\n'):
if branch.startswith('* '):
print('* ' + colored(branch[2:], 'green'))
else:
print(branch)

def _print_remote_branches(self):
"""Print output if self._print_output is True"""

for branch in self.repo.git.branch('-r').split('\n'):
if ' -> ' in branch:
components = branch.split(' -> ')
print(' ' + colored(components[0], 'red') + ' -> ' + components[1])
else:
print(colored(branch), 'red')

def _repo(self):
"""Create Repo instance for self.repo_path
Expand Down
13 changes: 7 additions & 6 deletions src/clowder/model/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,13 @@ def branch(self, local=False, remote=False):
"""

repo = ProjectRepo(self.full_path(), self.remote, self.ref)
if not is_offline() and remote:
if self.fork is None:
repo.fetch(self.remote, depth=self.depth)
else:
repo.fetch(self.fork.remote_name)
repo.fetch(self.remote)
# TODO: Rethink aggressively fetching for printing remote branches
# if not is_offline() and remote:
# if self.fork is None:
# repo.fetch(self.remote, depth=self.depth)
# else:
# repo.fetch(self.fork.remote_name)
# repo.fetch(self.remote)

repo.print_branches(local=local, remote=remote)

Expand Down

0 comments on commit 17e025f

Please sign in to comment.