sickill/git-dude — Issue #22: Fails handling fetch results other than new branch/tag/commit
Author: digitaljhelms
Created: 2011-12-15 21:00:24+00:00
State: open

**Error occurring:**

```sh
fatal: ambiguous argument '+': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions
```

**Working example of a `git fetch` which indicates a force-pushed branch ref in it's output:**

```sh
$ git fetch
remote: Counting objects: 78, done.
remote: Compressing objects: 100% (18/18), done.
remote: Total 48 (delta 28), reused 48 (delta 28)
Unpacking objects: 100% (48/48), done.
From github.com:Username/repo
+ 83e93db...b212eee branch-name -> origin/branch-name (forced update)
```

**Workflow:**

The output of `git fetch 2>&1 | grep -F -- '->' | sed -E 's/^\s+\+\s+//'` ([git-dude#L71](https://github.com/sickill/git-dude/blob/0d855f906d4a6d3052a9a23a6db58c4efaab9085/git-dude#L71)) is passed to `awk` (via a case statement) multiple times, each of which assigns a column of the output to a variable used by the notifier.

Piped output from working example:

```sh
$ git fetch 2>&1 | grep -F -- '->' | sed -E 's/^\s+\+\s+//'
+ 83e93db...b212eee branch-name -> origin/branch-name (forced update)
```

**Cause of error:**

The case statement has values for new branch ([git-dude#L85](https://github.com/sickill/git-dude/blob/0d855f906d4a6d3052a9a23a6db58c4efaab9085/git-dude#L85)), new tag ([git-dude#L89](https://github.com/sickill/git-dude/blob/0d855f906d4a6d3052a9a23a6db58c4efaab9085/git-dude#L89)), and new commits ([git-dude#L79](https://github.com/sickill/git-dude/blob/0d855f906d4a6d3052a9a23a6db58c4efaab9085/git-dude#L79)). However, because ".." is also included in the output for a force-pushed branch, but *not as the first column in the output*, it's matched by the "new commit" case and `awk` assigns an output flag to the `commit_range` variable. For instance, if the output from the `git fetch` above is sent to `awk` ([git-dude#L80](https://github.com/sickill/git-dude/blob/0d855f906d4a6d3052a9a23a6db58c4efaab9085/git-dude#L80)) it would result in the following:

```sh
$ echo " + 83e93db...b212eee branch-name -> origin/branch-name (forced update)" | awk '{ print $1 }'
+
```

In the case of a force-pushed branch, a `+` symbol is the first column in the output, not the abbreviated SHA-1 commit range, and thus the error. Similar issues may occur for other scenarios, such as deleted refs returned in the `git fetch` output which are prefixed with a `-` symbol.