bradleyfalzon / revgrep

Filters output from static analysis tools, showing only recently changed lines of code
Apache License 2.0
103 stars 15 forks source link

General `git` command-line issues. #16

Open puellanivis opened 5 years ago

puellanivis commented 5 years ago

If git diff is run against a branch name or commit reference that is also a file, git diff will error out, and report that it has an ambiguous argument. Worse, if the commit reference does not exist, but the file does, then the git diff will happily only report changes in that single file.

In order to ensure that a commit reference is always taken as a commit reference, and only as a commit reference, you have to append -- after the commits. So, for revisionFrom = "master": git diff master -- is the unambiguous command-line. (git diff from to -- works as expected as well.)

Also, if one has a .gitconfig that has color.diff = always, the code that looks for changes silently breaks, since the lines starting with + are now starting with an ANSI color sequence instead. It’s recommended to always assume there could be some external default value-override set that could break the command-line output. Adding --color=never fixes this for git diff.

The note in the source about git ls-files showing directories, might be a result of some .gitconfig default overrides as well. Using git status --porcelain is the recommended way to get a reliably appropriate-for-script-processing output.

bradleyfalzon commented 5 years ago

Thanks @puellanivis, do you have time to submit a PR and I'll address these.

puellanivis commented 5 years ago

It should not be too hard, I’m pretty sure I already have most of it done already. So, making sure all the approvals for contributing to open source software from my employer will be harder, even if they just say, “yeah, do it.” 😆