def sync_branch(self, branch): """Sync clowder repo to specified branch""" try: repo = Repo(self.clowder_path) except: repo_path_output = colored(self.clowder_path, 'cyan') print("Failed to create Repo instance for " + repo_path_output) else: if git_is_detached(self.clowder_path): try: repo.git.checkout(branch) except: print("Failed to checkout branch " + branch) print_exiting() if repo.active_branch.name != branch: try: repo.git.checkout(branch) except: print("Failed to checkout branch " + branch) print_exiting() self._validate() self.print_status() git_pull(self.clowder_path) self.symlink_yaml()
def sync(self): """Sync clowder repo""" self._validate() self.print_status() if not git_is_detached(self.clowder_path): git_pull(self.clowder_path) self.symlink_yaml() else: print(' - HEAD is detached') print_exiting()
def format_ref_string(repo_path): """Return formatted repo ref name""" local_commits = git_new_local_commits(repo_path) upstream_commits = git_new_upstream_commits(repo_path) no_local_commits = local_commits == 0 or local_commits == '0' no_upstream_commits = upstream_commits == 0 or upstream_commits == '0' if no_local_commits and no_upstream_commits: status = '' else: local_commits_output = colored('+' + str(local_commits), 'yellow') upstream_commits_output = colored('-' + str(upstream_commits), 'red') status = ' (' + local_commits_output + '/' + upstream_commits_output + ')' if git_is_detached(repo_path): current_ref = git_current_sha(repo_path) return colored('(HEAD @ ' + current_ref + ')', 'magenta') else: current_branch = git_current_branch(repo_path) return colored('(' + current_branch + ')', 'magenta') + status
def test_git_is_detached(self): """Test git_is_detached() function""" self.assertFalse(git_is_detached(self.jules_project_path)) self.assertFalse(git_is_detached(self.kit_project_path)) self.assertTrue(git_is_detached(self.sasha_project_path))