Reputation: 879
I am trying to retrieve the path of a repository from the "git bash" shell in windows, as follows
user@CND7293ZVV MINGW64 /c/Work/git/repository/subfolder (master)
$ git rev-parse --show-toplevel
C:/Work/git/repository
The problem is that I want to use the ouptut path to use it from a bash script, but it is not in bash format. I want to get /c/Work/git/repository
. Is there any way to get the path in a way that can be used directly in the git bash shell?
extra information: The target is to store that path in a variable to be used inside a bash script, independently of whether I am running bash from a linux terminal, or when I am running from the git bash.
Update:
To be able to use the command inside the git-bash environment, and also inside native linux bash, we can use the following:
REPODIR=$(git rev-parse --show-toplevel)
# If we are inside mingw* environment, then we update the path to proper format
if [[ $(uname) == MINGW* ]] ; then REPODIR=$(cygpath -u "${REPODIR}"); fi; echo ${REPODIR}
Upvotes: 1
Views: 1173
Reputation: 18824
When running on the Git bash command line, you have an buildin utility with the name cygpath that does this:
$ cygpath -u "C:/Work/git/repository"
/c/Work/git/repository
This can be combined with your existing command to do everything on 1 line:
$ cygpath -u "$(git rev-parse --show-toplevel)"
/c/Work/git/repository
Upvotes: 3