Skip to content

Fix GitX quitting when a commit is clicked in a missing repository - #653

Merged
hannesa2 merged 1 commit into
gitx:masterfrom
goneng:fix-details-pane-abort-without-head
Sep 15, 2026
Merged

hannesa2 merged 1 commit into
gitx:masterfrom
goneng:fix-details-pane-abort-without-head

Conversation

@goneng

@goneng goneng commented Sep 15, 2026 •

Copy link
Copy Markdown
Collaborator

GitX quits, with no error and no warning, when you click a commit in a repository that is no longer where GitX left it: the folder was deleted or renamed, or it lived on a drive that has since been ejected. The window is simply gone.

Fixes #648.

Showing a commit the details pane has not shown before passes the current branch
name into the argument list the page is called with:

NSArray *arguments = @[ commit, [[repository headRef] simpleRef], ... ];

That name is nil in two independent ways. -headRef returns nil when the HEAD
lookup fails, when resolving it fails on a HEAD that is not unborn, or when the
resolved reference has no name; -simpleRef returns nil separately when the
specifier is not a simple ref. A nil in an array literal raises, so instead of
the pane going blank the application goes away.

The same expression appeared twice, and only the in place refresh guarded
itself, so the fix is one answer both callers share rather than a second guard
that the next caller could forget.

Test plan

  • Two tests over a repository with no readable HEAD, which is what
    [[PBGitRepository alloc] init] gives and needs neither libgit2 nor a
    repository on disk
  • Both fail before the change, the second with the exact crash:
    NSInvalidArgumentException: attempt to insert nil object from objects[1]
  • Full suite green after: 128 tests, 0 failures

Not reproduced end to end, since it needs a repository that opened normally and
then stopped being readable. The tests pin the condition instead.

@goneng goneng changed the title Fix the details pane aborting when HEAD cannot be read Fix GitX quitting when a commit is clicked in a missing repository Sep 15, 2026
GitX quits, with no error and no warning, when a commit is clicked in a
repository that is no longer where GitX left it: the folder deleted or
renamed, or the drive it sat on ejected. Showing a commit the details
pane has not shown before puts the name of the current branch into the
argument list the page is called with, and that name is nothing at all
once HEAD can no longer be read. A nil in an array literal raises, and
nothing catches it, so the window goes rather than going blank.

* Answer the current branch name in one place, so a repository with no
  readable HEAD names no branch rather than nothing at all
* Have both the first load and the in place refresh ask for it there,
  the refresh having been the only one of the two that guarded itself
@goneng
goneng force-pushed the fix-details-pane-abort-without-head branch from 9b4d3c0 to ece6ee8 Compare September 15, 2026 18:39
@goneng
goneng marked this pull request as ready for review September 15, 2026 18:41
@goneng goneng added the bugfix label Sep 15, 2026

// The name goes straight into the argument list the page is called with, and a
// nil there aborts the application rather than leaving the pane blank.
- (void)testTheArgumentsForACommitCanBeBuiltWhenHeadCannotBeRead

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, even with a test

@hannesa2
hannesa2 merged commit a3f6995 into gitx:master Sep 15, 2026
3 checks passed
@goneng
goneng deleted the fix-details-pane-abort-without-head branch September 15, 2026 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clicking a commit quits GitX when its repository has gone away

2 participants