From 169bf3c95dd528a9aa11a892fa9bd313c8b39ddd Mon Sep 17 00:00:00 2001 From: grimmer Date: Sun, 15 Aug 2021 16:23:37 +0800 Subject: [PATCH] Add get_current_branch method in class Git --- poetry/core/vcs/git.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/poetry/core/vcs/git.py b/poetry/core/vcs/git.py index 1633ad090..d139546ad 100644 --- a/poetry/core/vcs/git.py +++ b/poetry/core/vcs/git.py @@ -223,6 +223,25 @@ def checkout(self, rev: str, folder: Optional[Path] = None) -> str: return self.run(*args) + def get_current_branch(self, folder=None): + args = [] + + if folder is None and self._work_dir: + folder = self._work_dir + + if folder: + print("folder is not empty string 2") + args += [ + "--git-dir", + (folder / ".git").as_posix(), + "--work-tree", + folder.as_posix(), + ] + + args += ["rev-parse", "--abbrev-ref", "HEAD"] + + return self.run(*args) + def rev_parse(self, rev: str, folder: Optional[Path] = None) -> str: args = [] if folder is None and self._work_dir: