-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
po_mode: Implement suggestions from review
- Loading branch information
Showing
5 changed files
with
119 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,48 @@ | ||
from collections.abc import Sequence | ||
from pathlib import Path | ||
from subprocess import CalledProcessError | ||
|
||
from git import Repo | ||
|
||
from .config import RepositoryConfig | ||
from .logging import LOGGER | ||
|
||
def repository_in_clean_state(path: Path, branch: str) -> Repo: | ||
|
||
def repository_in_clean_state( | ||
repo_config: RepositoryConfig, | ||
repo_name: str, | ||
) -> Repo: | ||
LOGGER.info("Cleaning up and updating %s repository", repo_name) | ||
try: | ||
return _repository_in_clean_state( | ||
repo_config.path, | ||
repo_config.branch, | ||
) | ||
except Exception as e: | ||
LOGGER.error("Error while cleaning up and updating %s repository", repo_name) | ||
LOGGER.exception(e) | ||
raise e | ||
|
||
|
||
def _repository_in_clean_state(path: Path, branch: str) -> Repo: | ||
repo = Repo(path) | ||
repo.git.reset("--hard") | ||
repo.remotes.origin.fetch() | ||
repo.git.checkout(branch) | ||
repo.git.reset("--hard", f"origin/{branch}") | ||
return repo | ||
|
||
|
||
def commit_and_push_files( | ||
repo: Repo, | ||
files_to_push_to_repo: Sequence[Path], | ||
) -> None: | ||
try: | ||
repo.index.add(files_to_push_to_repo) | ||
repo.index.commit("Updateing files") | ||
repo.remotes.origin.push() | ||
except CalledProcessError as e: | ||
LOGGER.error("Committing and pushing files failed") | ||
LOGGER.exception(e) | ||
raise e | ||
LOGGER.info("Committing and pushing files succeeded") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.