karan / joe

:running: A .gitignore magician in your command line
http://karan.github.io/joe/
MIT License
2.88k stars 210 forks source link

Output piped via PowerShell on Windows into .gitignore not recognized by git #61

Open paulirwin opened 9 years ago

paulirwin commented 9 years ago

Steps to reproduce:

  1. Open PowerShell to a new empty git repo
  2. Create a file or folder (with a file in the folder) that should be ignored, such as a "bin" folder for the "visualstudio" template
  3. Run joe visualstudio > .gitignore per the documentation in README
  4. Run git add .
  5. Run git status. Note that the "bin" folder has been added as a staged change, despite being ignored.

This is due to PowerShell using some UTF-8 marks that git doesn't like but for some reason git doesn't warn you. You can see this output in Atom, with some line ending issues as well (note the presumably Unicode-related marks at the beginning of the file):

image

Note that if you run echo "bin/" > .gitignore it also doesn't work - so this is definitely a problem with either PowerShell or git, and not a problem with Joe. Also of note is that the piping works if this is run from Git Bash which is installed with Git for Windows. However, this means that either Joe should have functionality to create the .gitignore without redirecting standard output (such as a --create flag), and the documentation should at least be updated to note that redirecting output with > in PowerShell results in a file that is not usable by git. Unless there's some other way to work around this limitation in PowerShell.

awarrenlove commented 9 years ago

You probably want to look into https://technet.microsoft.com/en-us/library/hh849882.aspx. PowerShell defaults to Unicode output if you use '>', so you must instead pipe to out-file and set the encoding there.

paulirwin commented 9 years ago

@awarrenlove Workarounds like that are acceptable, but updating the docs/readme to reflect that would be in order (if that's the only option) since the readme as-is doesn't work in PowerShell.