Skip to content

Commit

Permalink
Add branch, clone_params, pull_params, checkout_params parame…
Browse files Browse the repository at this point in the history
…ter to `git.clone-repo` invocation
  • Loading branch information
TheSuperiorStanislav committed Feb 28, 2024
1 parent 5c6435f commit 2c9fb9b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ We follow [Semantic Versions](https://semver.org/).

## unreleased

Fix `git.blame-copy` in case if merge conflict between files occurs.
- Fix `git.blame-copy` in case if merge conflict between files occurs.
- Add `branch`, `clone_params`, `pull_params`, `checkout_params` parameter to `git.clone-repo` invocation

## 1.0.0

Expand Down
44 changes: 39 additions & 5 deletions saritasa_invocations/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,50 @@ def clone_repo(
context: invoke.Context,
repo_link: str,
repo_path: str | pathlib.Path,
branch: str = "",
clone_params: str = "",
pull_params: str = "",
checkout_params: str = "",
) -> None:
"""Clone repo for work to folder."""
if not pathlib.Path(repo_path).exists():
printing.print_success(f"Cloning {repo_link} repository...")
context.run(f"git clone {repo_link} {repo_path}")
printing.print_success(f"Successfully cloned to '{repo_path}'!")
printing.print_success(
f"Cloning `{repo_link}` repository to `{repo_path}`",
)
context.run(f"git clone {repo_link} {repo_path} {clone_params}")
checkout_to_branch(
context,
repo_path=repo_path,
branch=branch,
checkout_params=checkout_params,
)
printing.print_success(f"Successfully cloned to `{repo_path}`")
else:
printing.print_success(f"Pulling changes for {repo_link}...")
printing.print_success(
f"Pulling changes for `{repo_link}` in `{repo_path}`",
)
checkout_to_branch(
context,
repo_path=repo_path,
branch=branch,
checkout_params=checkout_params,
)
with context.cd(repo_path):
context.run("git pull")
context.run(f"git pull {pull_params}")


def checkout_to_branch(
context: invoke.Context,
repo_path: str | pathlib.Path,
branch: str,
checkout_params: str = "",
) -> None:
"""Checkout to repo's branch."""
if not branch:
return
with context.cd(repo_path):
printing.print_success(f"Checkout to `{branch}` branch")
context.run(f"git checkout {branch} {checkout_params}")


@invoke.task
Expand Down

0 comments on commit 2c9fb9b

Please sign in to comment.