Skip to content
This repository has been archived by the owner on Aug 25, 2024. It is now read-only.

Commit

Permalink
feature: git: repo default branch: Output git_remote while we are there
Browse files Browse the repository at this point in the history
Signed-off-by: John Andersen <[email protected]>
  • Loading branch information
pdxjohnny committed Jul 28, 2022
1 parent fcd799d commit e9e43d6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 2 additions & 0 deletions feature/git/dffml_feature_git/feature/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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]",
Expand Down
7 changes: 4 additions & 3 deletions feature/git/dffml_feature_git/feature/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]):
Expand All @@ -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(
Expand Down

0 comments on commit e9e43d6

Please sign in to comment.