Diff: Fixed staged file diff in a commit-less repo
commit432bb0cc650ce07f6514bfeb598edcc4a7652662
authormmargoliono <2543851+mmargoliono@users.noreply.github.com>
Mon, 12 Jul 2021 07:51:58 +0000 (12 17:51 +1000)
committermmargoliono <2543851+mmargoliono@users.noreply.github.com>
Mon, 12 Jul 2021 08:28:41 +0000 (12 18:28 +1000)
treec84643d401c2983595eaa76aee76da2f198191f4
parent97a86335c949bb12f315c98b5e26ce3db649fc19
Diff: Fixed staged file diff in a commit-less repo

When there is no commit in the repo, there is no HEAD revision.
Therefore the diff command returns an error (fatal: bad revision
'head'), and git-cola then use empty text as the diff fallback.

To fix the issue, the diff_helper is updated to check if `ref` exists,
and if `ref` doesn't exist, we drop it and not pass it to the git diff.
The check is done through the rev_parse wrapper in gitcmds,
which will simply return back `ref`, when it is not in git.

When viewing the diff of a staged file in a commit-less repo,
the ref would be 'HEAD'. Dropping 'HEAD' from parameter will make git
compare the staged file against file in the working directory.

Issue: #1110
Reported-By: kyanres
Signed-off-by: mmargoliono
cola/gitcmds.py