Skip to content

Commit

Permalink
Alter rev-parse syntax to support msys git
Browse files Browse the repository at this point in the history
On windows, msys and cygwin versions of git need braces to be escaped when they
are invoked via subprocess.  (This appears to be is a side effect of the machinery
that converts windows paths to posix-like paths for the executable).

If they are not escaped, then "rev^{commit]" becomes a meaningless "rev^commit"
to an msys git, resulting in an error.

In contrast, we do not want to escape the braces if passing "rev^{commit}" to any
other form of git.  We can avoid having to decide whether escaping is needed by
using the alternative notation "^0".
  • Loading branch information
donkopotamus committed Jul 13, 2020
1 parent b19873a commit 31f42cf
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions poetry/vcs/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,15 @@ def rev_parse(self, rev, folder=None): # type: (...) -> str
folder.as_posix(),
]

# We need "^{commit}" to ensure that the commit SHA of the commit the
# tag points to is returned, even in the case of annotated tags.
args += ["rev-parse", rev + "^{commit}"]
# 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.
#
# We deliberately avoid the "^{commit}" syntax itself as on some
# platforms (cygwin/msys to be specific), the braces are interpreted
# as special characters and would require escaping, while on others
# they should not be escaped.
args += ["rev-parse", rev + "^0"]

return self.run(*args)

Expand Down

0 comments on commit 31f42cf

Please sign in to comment.