Skip to content

Commit

Permalink
Add a convenience method to retrieve the current git branch
Browse files Browse the repository at this point in the history
Co-authored-by: grimmer0125 <5940941+grimmer0125@users.noreply.github.com>
  • Loading branch information
sdispater and grimmer0125 committed Aug 20, 2021
1 parent 2b7673e commit 9e223ad
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions poetry/core/vcs/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,6 @@ def rev_parse(self, rev: str, folder: Optional[Path] = None) -> str:
if folder is None and self._work_dir:
folder = self._work_dir

if folder:
args += [
"--git-dir",
(folder / ".git").as_posix(),
"--work-tree",
folder.as_posix(),
]

# We need "^0" (an alternative to "^{commit}") to ensure that the
# commit SHA of the commit the tag points to is returned, even in
# the case of annotated tags.
Expand All @@ -285,7 +277,15 @@ def rev_parse(self, rev: str, folder: Optional[Path] = None) -> str:
# they should not be escaped.
args += ["rev-parse", rev + "^0"]

return self.run(*args)
return self.run(*args, folder=folder)

def get_current_branch(self, folder: Optional[Path] = None) -> str:
if folder is None and self._work_dir:
folder = self._work_dir

output = self.run("symbolic-ref", "--short", "HEAD", folder=folder)

return output.strip()

def get_ignored_files(self, folder: Optional[Path] = None) -> list:
args = []
Expand Down

0 comments on commit 9e223ad

Please sign in to comment.