Skip to content

Commit

Permalink
Use -- to separate arguments from paths
Browse files Browse the repository at this point in the history
Some paths have characters which make them ambiguous as to whether they're a path or argument

For example,

    $ git log --follow --find-renames=40% --reverse a/b-c-d/e.txt
    fatal: ambiguous argument 'a/b-c-d/e.txt': unknown revision or path not in the working tree.
    Use '--' to separate paths from revisions, like this:
    'git <command> [<revision>...] -- [<file>...]'

    $ echo $?
    128

compared to

    $ git log --follow --find-renames=40% --reverse -- a/b-c-d/e.txt

    $ echo $?
    0
  • Loading branch information
JakeWharton committed Apr 21, 2021
1 parent a4a86aa commit 114a31f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ This document is intended for Spotless developers.
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`).

## [Unreleased]
### Fixed
* Explicitly separate target file from git arguments when parsing year for license header to prevent command from failing on argument-like paths ([#847](https://github.com/diffplug/spotless/pull/847))

## [2.13.3] - 2021-04-20
### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ private String setLicenseHeaderYearsFromGitHistory(String raw, File file) throws
}

private static String parseYear(String cmd, File file) throws IOException {
String fullCmd = cmd + " " + file.getAbsolutePath();
String fullCmd = cmd + " -- " + file.getAbsolutePath();
ProcessBuilder builder = new ProcessBuilder().directory(file.getParentFile());
if (FileSignature.machineIsWin()) {
builder.command("cmd", "/c", fullCmd);
Expand Down
2 changes: 2 additions & 0 deletions plugin-gradle/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`).

## [Unreleased]
### Fixed
* Explicitly separate target file from git arguments when parsing year for license header to prevent command from failing on argument-like paths ([#847](https://github.com/diffplug/spotless/pull/847))

## [5.12.2] - 2021-04-20
### Fixed
Expand Down
2 changes: 2 additions & 0 deletions plugin-maven/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`).

## [Unreleased]
### Fixed
* Explicitly separate target file from git arguments when parsing year for license header to prevent command from failing on argument-like paths ([#847](https://github.com/diffplug/spotless/pull/847))

## [2.10.2] - 2021-04-20
### Fixed
Expand Down

0 comments on commit 114a31f

Please sign in to comment.