-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for POE_GIT_DIR and POE_GIT_ROOT variables in config
- Loading branch information
Showing
17 changed files
with
735 additions
and
488 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
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 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 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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import shutil | ||
from pathlib import Path | ||
from subprocess import PIPE, Popen | ||
from typing import Optional, Tuple | ||
|
||
|
||
class GitRepo: | ||
def __init__(self, seed_path: Path): | ||
self._seed_path = seed_path | ||
self._path: Optional[Path] = None | ||
self._main_path: Optional[Path] = None | ||
|
||
@property | ||
def path(self) -> Optional[Path]: | ||
if self._path is None: | ||
self._path = self._resolve_path() | ||
return self._path | ||
|
||
@property | ||
def main_path(self) -> Optional[Path]: | ||
if self._main_path is None: | ||
self._main_path = self._resolve_main_path() | ||
return self._main_path | ||
|
||
def init(self): | ||
self._exec("init") | ||
|
||
def delete_git_dir(self): | ||
shutil.rmtree(self._seed_path.joinpath(".git")) | ||
|
||
def _resolve_path(self) -> Optional[Path]: | ||
""" | ||
Resolve the path of this git repo | ||
""" | ||
proc, captured_stdout = self._exec( | ||
"rev-parse", "--show-superproject-working-tree", "--show-toplevel" | ||
) | ||
if proc.returncode == 0: | ||
captured_lines = ( | ||
line.strip() for line in captured_stdout.decode().strip().split("\n") | ||
) | ||
longest_line = sorted((len(line), line) for line in captured_lines)[-1][1] | ||
return Path(longest_line) | ||
return None | ||
|
||
def _resolve_main_path(self) -> Optional[Path]: | ||
""" | ||
Resolve the path of this git repo, unless this repo is a git submodule, | ||
then resolve the path of the main git repo. | ||
""" | ||
proc, captured_stdout = self._exec( | ||
"rev-parse", "--show-superproject-working-tree", "--show-toplevel" | ||
) | ||
if proc.returncode == 0: | ||
return Path(captured_stdout.decode().strip().split("\n")[0]) | ||
return None | ||
|
||
def _exec(self, *args: str) -> Tuple[Popen, bytes]: | ||
proc = Popen( | ||
["git", *args], | ||
cwd=self._seed_path, | ||
stdout=PIPE, | ||
stderr=PIPE, | ||
) | ||
(captured_stdout, _) = proc.communicate() | ||
return proc, captured_stdout |
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
Oops, something went wrong.