Skip to content

Commit

Permalink
Change origin to remote_url in git functions
Browse files Browse the repository at this point in the history
Less ambiguous this way
  • Loading branch information
lainets committed Apr 25, 2023
1 parent 47f1531 commit 59045d4
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions util/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ def git_call(path: str, command: str, cmd: List[str], include_cmd_string: bool =
return True, cmd_str + response.stdout


def clone(path: str, origin: str, branch: str, *, logger: Logger = default_logger) -> bool:
def clone(path: str, remote_url: str, branch: str, *, logger: Logger = default_logger) -> bool:
Path(path).mkdir(parents=True, exist_ok=True)

success, logstr = git_call(".", "clone", ["clone", "-b", branch, "--recursive", origin, path])
success, logstr = git_call(".", "clone", ["clone", "-b", branch, "--recursive", remote_url, path])
logger.info(logstr)
return success


def checkout(path: str, origin: str, branch: str, *, logger: Logger = default_logger) -> bool:
def checkout(path: str, remote_url: str, branch: str, *, logger: Logger = default_logger) -> bool:
success = True
# set the path beforehand, and handle logging
def git(command: str, cmd: List[str]):
Expand Down Expand Up @@ -76,26 +76,26 @@ def git(command: str, cmd: List[str]):
return success


def has_origin(path: str, origin: str) -> bool:
def has_remote_url(path: str, remote_url: str) -> bool:
success, origin_url = git_call(path, "remote", ["remote", "get-url", "origin"], include_cmd_string=False)
return origin == origin_url.strip()
return remote_url == origin_url.strip()


def clone_if_doesnt_exist(path: str, origin: str, branch: str, *, logger: Logger = default_logger) -> Optional[bool]:
def clone_if_doesnt_exist(path: str, remote_url: str, branch: str, *, logger: Logger = default_logger) -> Optional[bool]:
"""
Clones a repo to <path> if it hasnt been already.
Returns None if the repo already exists, otherwise returns whether the clone was successful.
"""
success = False
if Path(path, ".git").exists():
if has_origin(path, origin):
if has_remote_url(path, remote_url):
return None

logger.info("Wrong origin in repo, recloning\n\n")

rm_path(path)
success = clone(path, origin, branch, logger=logger)
success = clone(path, remote_url, branch, logger=logger)

return success and (Path(path) / ".git").exists()

Expand Down

0 comments on commit 59045d4

Please sign in to comment.