Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Staged diffs aren't displayed in a repository without commits #1110

Open
kyanres opened this issue Feb 3, 2021 · 4 comments
Open

Staged diffs aren't displayed in a repository without commits #1110

kyanres opened this issue Feb 3, 2021 · 4 comments

Comments

@kyanres
Copy link

kyanres commented Feb 3, 2021

Hello!

To reproduce :

mkdir test && cd test
git init
echo -e "a\nb" > foo
git cola

Then use git cola to stage the file.

Observed behavior :
When foo is Untracked, the Diff view shows its contents.
When foo is Staged, the Diff view is empty.

Expected behavior :
I need to see what's staged before committing :-) + to be able to unstage some lines.

Hope that helps.
I got around that problem by doing a first commit for .gitignore and squashing it later with rebase -i --root

git version 2.25.1
cola version 3.6

@nyanpasu64
Copy link

nyanpasu64 commented Jun 16, 2021

Still an issue on commit f4cdf65.

This occurs in all repositories with no HEAD (both newly git init repos, and git checkout --orphan $branch_name).

I had written a bug report, but decided to not file it after finding this existing issue.

My original bug report In a repo with no HEAD (either after `git init` or `git checkout --orphan`), if I create a file and stage it, Git Cola's Diff pane doesn't show the contents of the file.

In a repo with a HEAD, if I create a file and stage it, Git Cola's Diff pane does show the contents of the file (on a green background, indicating the entire file is added relative to HEAD).

I'm using the git-cola-git AUR package on commit f4cdf65.

  • git init foo
  • cd foo
  • echo hi>filename
  • git-cola
    • Click "filename". ("hi" appears in the Diff pane.)
    • Double-click "filename" to stage the file. (The text in the diff pane disappears.)
    • If you click "filename" again, the diff pane remains empty. I think this is a bug.
    • Close the Git Cola window.
  • git reset
  • git commit --allow-empty -m "test"
    • (Right now, HEAD exists, but points to an empty tree.)
  • git-cola
    • Stage "filename". (The text in the file disappears. Is this normal?)
    • If you click "filename", the text reappears in the diff pane, as expected.

mmargoliono added a commit to mmargoliono/git-cola that referenced this issue Jul 12, 2021
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: git-cola#1110
Reported-By: kyanres
Signed-off-by: mmargoliono
mmargoliono added a commit to mmargoliono/git-cola that referenced this issue Jul 12, 2021
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: git-cola#1110
Reported-By: kyanres
Signed-off-by: mmargoliono
davvid added a commit to davvid/git-cola that referenced this issue Jul 17, 2021
Keep diff_helper() simpler by lifting the ref verification up
into the DiffStaged command. This ensures that other diff_helper()
use cases are not impacted by the fix for git-cola#1110.

Related-to: git-cola#1149
Signed-off-by: David Aguilar <davvid@gmail.com>
@nyanpasu64
Copy link

Using the git-cola-git AUR package, pointing to main 74e94ae. Now showing a file diff works, but staged images don't show anything. And if I stage an image, quit and reopen Git Cola, and scroll on the image, the app crashes:

Traceback (most recent call last):
  File "/usr/share/git-cola/lib/cola/widgets/imageview.py", line 330, in wheelEvent
    self.zoomROITo(scene_pos, sign)
  File "/usr/share/git-cola/lib/cola/widgets/imageview.py", line 214, in zoomROITo
    roi_dims = QtCore.QPointF(roi.width(), roi.height())
AttributeError: 'NoneType' object has no attribute 'width'
fish: Job 1, 'cola' terminated by signal SIGABRT (Abort)

davvid added a commit to davvid/git-cola that referenced this issue Aug 4, 2021
Some callbacks may fire before the scene has been initialized.
Guard against spurious mousewhell events.

Related-to: git-cola#1110
Signed-off-by: David Aguilar <davvid@gmail.com>
@davvid
Copy link
Member

davvid commented Aug 4, 2021

Thanks for the heads-up @nyanpasu64 -- I just pushed b63bc42 which should guard against the scenario you ran into. Interesting I couldn't reproduce it, but I added some extra guard checks.

BTW, I noticed the traceback above says /usr/share/... but if you're running from the source tree it should have a path that points into your git clone. You can verify this in the Help -> About dialog by checking the listed version.

Nonetheless, this should be better behaved going forward. Cheers

@nyanpasu64
Copy link

I'm using the git-cola-git AUR package, pointing to the newly pushed b63bc42:

Git Cola version 3.10.1 (v3.10-39-gb63bc427)
Linux-5.13.7-zen1-1-zen-x86_64-with-glibc2.33
Python (/usr/bin/python) 3.9.6 (default, Jun 30 2021, 10:22:16) [GCC 11.1.0]
Git 2.32.0
Qt 5.15.2
QtPy 1.9.0
PyQt5 5.15.4

When I put this file in an empty folder, then run git init, I get a preview before staging but not after staging (no console messages though). At least I no longer get a crash...

Warning sign.zip

Screenshot_20210804_210306_cola-test: master _home_nyanpasu64_code_cola-test
Screenshot_20210804_210308_cola-test: master _home_nyanpasu64_code_cola-test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants