Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a git alias to append to .gitignore

Tags:

git

bash

msysgit

I'm using git 1.9.0 on Windows (msysgit) and I have the following alias:

ignore = "!f() { echo $1 >> \"${GIT_PREFIX}.gitignore\"; }; f"

And I use it like so:

$ git ignore /Directory/Subdir/

This should append to my .gitignore file within the current directory, or create it if it doesn't exist. However for some reason the path I'm passing in is being converted to an absolute path and I'm not sure why:

Here is what is being appended to my .gitignore:

C:/Program Files (x86)/Git/Docs/Doxygen/html/

Any reason why this is happening?

EDIT

If I just use the command like so:

$ git ignore Docs/Doxygen/html

It will not convert the path. So it looks like the forward-slash at the beginning is causing some problems in the shell before the parameter is passed to the alias. Encasing it in quotes doesn't fix it either. I'm at a loss!

EDIT #2

Tried this:

$ git ignore \/Docs/Doxygen/html/
C:/Program Files (x86)/Git/Docs/Doxygen/html/

Backslash prior to the forward slash does not fix it either.

EDIT #3

It's a bug in msysgit I think. I did the same thing in cygwin and look what happens:

$ git ignore /Docs/Doxygen/html/
/Docs/Doxygen/html/

:-(

like image 826
void.pointer Avatar asked Nov 10 '22 12:11

void.pointer


1 Answers

The conversion rules for msys are documented on the POSIX path conversion page.

An argument with a leading / is converted up to the first /

According to the documentation you should prefix your path with // to have only the first slash undergo the conversion, and convert forward slashes to backslashes:

//foo\bar ➜ /foo/bar ➜ \ converted to /

Try,

$ git ignore "//Directory\Subdir\"

And,

$ git ignore //Directory\\Subdir\\
like image 51
mockinterface Avatar answered Nov 15 '22 05:11

mockinterface