From e9e43d6559154e5449a6e0c47777d73b7b8f9a5b Mon Sep 17 00:00:00 2001 From: John Andersen Date: Wed, 27 Jul 2022 21:32:47 -0700 Subject: [PATCH] feature: git: repo default branch: Output git_remote while we are there Signed-off-by: John Andersen --- feature/git/dffml_feature_git/feature/definitions.py | 2 ++ feature/git/dffml_feature_git/feature/operations.py | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/feature/git/dffml_feature_git/feature/definitions.py b/feature/git/dffml_feature_git/feature/definitions.py index 12377b3db2..8023b146bb 100644 --- a/feature/git/dffml_feature_git/feature/definitions.py +++ b/feature/git/dffml_feature_git/feature/definitions.py @@ -19,6 +19,7 @@ class GitRepoCheckedOutSpec(NamedTuple): URLType = NewType("URL", str) NoGitBranchGivenType = NewType("no_git_branch_given", bool) GitBranchType = NewType("git_branch", str) +GitRemoteType = NewType("git_remote", str) definitions = [ Definition(name="quarter_start_date", primitive="int"), @@ -28,6 +29,7 @@ class GitRepoCheckedOutSpec(NamedTuple): Definition(name="git_repo_ssh_key", primitive="string", default=None), Definition(name="valid_git_repository_URL", primitive="boolean"), new_type_to_defininition(GitBranchType), + new_type_to_defininition(GitRemoteType), Definition( name="git_repository", primitive="Dict[str, str]", diff --git a/feature/git/dffml_feature_git/feature/operations.py b/feature/git/dffml_feature_git/feature/operations.py index 6f494cc688..44b4ced085 100644 --- a/feature/git/dffml_feature_git/feature/operations.py +++ b/feature/git/dffml_feature_git/feature/operations.py @@ -135,7 +135,7 @@ async def clone_git_repo(self, URL: str, ssh_key: str = None): @op( inputs={"repo": git_repository}, - outputs={"branch": git_branch}, + outputs={"branch": git_branch, "remote": git_remote}, conditions=[no_git_branch_given], ) async def git_repo_default_branch(repo: Dict[str, str]): @@ -146,8 +146,9 @@ async def git_repo_default_branch(repo: Dict[str, str]): if not list(filter(bool, branches)): return main = [branch for branch in branches if "->" in branch][0].split()[-1] - main = main.split("/")[-1] - return {"branch": main} + # origin/HEAD -> origin/main + # {'branch': 'main', 'remote': 'origin'} + return dict(zip(["remote", "branch"], main.split("/", maxsplit=1))) @op(