← The journal

Gitsanity on iPhone Duo: Git History That Folds

I built a phone version of Gitsanity for fun, to see what designing for an iPhone Duo involves. It keeps a few megabytes of each repository and lays itself out closed, open flat and half folded, without a single line of code that asks which pose the phone is in.

I wrote this one for fun. I'm not sure anyone will use something on their phone to look at Git repositories.

But I find it interesting, dare I say fascinating, to look at the activity of an open source project: what the team is working on this month, who showed up, who went quiet, which files never stop changing. Gitsanity does that on my Mac. I wanted it on the iPhone Duo, and I wanted to see what designing for a phone that folds actually involves.

Here is a minute of it, on Zed's repository:

Quick Links

There is no git on a phone

The Mac app opens a folder you already have. A phone has no folder and no git. So the Rust engine, the same one behind the terminal version and the Mac app, learned to download a repository itself: gitoxide over HTTPS, with rustls for TLS, straight into the app's own storage.

Then comes the part that makes this reasonable on a phone. The engine reads the repository once, writes its index, and the app deletes the download. Every screen is computed from the index alone.

These are from the library in the video, measured in the simulator:

RepositoryCommitsDownloadedKept on the phone
swiftlang/swift214,8291.52 GB15.9 MB
omacom/omarchy8,8131.35 GB725 KB
zed-industries/zed41,149606 MB3.2 MB
rails/rails101,615346 MB7.5 MB
elixir-lang/elixir23,04091.5 MB1.5 MB
google-gemini/gemini-cli6,651122 MB590 KB

Before gemini-cli was added in the video, the library held nine repositories. As downloads they would take 4.2 GB. They sit in 31 MB. The library shows what each one takes and the total, because on a phone I want to know.

It has a price, and the app says so where it applies. Without the download there are no tags, no other branches, and only the first line of each commit message. If you want those, a switch in Settings keeps the downloads.

The library on the closed iPhone Duo: 31 MB for nine repositories

On the Swift side this is one new call on the bridge. The Mac app opens a repository, the phone opens an index with no repository behind it:

/// Everything that is computed from the index works; tags, other branches
/// and commit message bodies need the repository and come back empty.
#[uniffi::constructor]
pub fn open_archive(index_path: String, name: String) -> Res<Arc<Self>> { /* ... */ }

Three poses, and no code that asks which one

An iPhone Duo is two devices. Closed, it's a narrow phone with an outer display. Open flat, the inner display is closer to a small tablet, with a fold down the middle. And it can sit half folded, like a book, with each half facing you at its own angle.

The obvious way is three layouts and a switch. What the app does instead: nothing in it is laid out per pose. It is built from three standard pieces, and the system does the folding.

  1. A split view for the whole app: library on one side, repository on the other.
  2. A tab view and a toolbar, the standard ones. On the outer display the system draws them down the side instead of along the bottom. I didn't write that, I just didn't get in its way.
  3. An arrangement view wherever two things belong together: a list and the row you picked, or the figures and the lists under them.

The arrangement view is the container Apple gives the iPhone Duo for exactly this. Two panes go in. They come out side by side when the space is wider than tall, one above the other when it's taller, and one on each side of the fold when the phone is half folded, with nothing across the hinge.

struct ListDetail<Rows: View, Detail: View>: View {
    @Environment(\.horizontalSizeClass) private var width
    @ViewBuilder let rows: Rows
    @ViewBuilder let detail: Detail

    var body: some View {
        if width == .regular {
            ArrangementView {
                // The pane's edge is not the display's: without this the
                // figures at the end of a row touch the second pane.
                rows.safeAreaPadding(.trailing, 14)
            } secondary: {
                detail.secondaryPane()
            }
            .arrangementViewStyle(.split)
        } else {
            rows
        }
    }
}

That's the only question the layout asks: is this space wide or narrow? People, Files and Commits all go through it.

Closed

One column. Five tabs, Overview, People, Files, Commits and Ownership, over a shared time range. Tap a contributor, a file or a commit and it opens as a screen of its own, with a Back button. It's an iPhone app.

Open flat

Now there's room for the list and what you picked, so the pushed screen becomes the second pane.

Open flat: the overview, figures and chart on one side, the lists on the other

This is where the first version was wrong. I unfolded the simulator and the library sat on the left with the repository squeezed into the other two thirds. That leftover space is taller than wide, so the arrangement view did what it's told and stacked its two panes. Half the height each. On the best display of the device, the overview looked cramped.

The fix was to give an open repository the whole inner display. The library slides over it from a button in the bar and goes away when you pick something:

public var body: some View {
    if isPhone {
        split.navigationSplitViewStyle(.prominentDetail)
    } else {
        split
    }
}

Open flat: a contributor's year beside the list of people

An iPad keeps the library beside the repository, it has the room. A smaller choice with the same reasoning: grids of panels always have an even number of columns on the wide display. The fold then falls between two panels and never through a number.

A commit and the files it touched, on the open display

Half folded

Nothing had to change for this one. I set the simulator to a partly folded pose and the system moved the two panes of every arrangement view apart, one to each half, and left the fold clear. The list is on the left page, the detail on the right page.

Half folded like a book: files on one page, the selected file on the other

Open the library in this pose and it takes the left half, the repository the right. The Add Repository sheet stays on one half too.

Folding must not lose your place

The one rule I did have to implement myself. Fold the phone shut in the middle of the Ownership screen of Zed and the outer display should be on the Ownership screen of Zed, same time range, same row selected.

SwiftUI rebuilds the views when the display changes, so nothing that matters lives in a view. The tab, the range and the selection sit in a model per repository, and the app keeps those models for as long as it runs:

/// A model is kept for as long as the app runs, so coming back to a
/// repository, or folding and opening the device, finds every screen
/// where it was left.
func model(for entry: LibraryEntry) -> RepositoryModel {
    if let model = models[entry.id], model.entry.read == entry.read { return model }
    let model = RepositoryModel(entry: entry)
    models[entry.id] = model
    return model
}

Ownership, half folded: who holds the knowledge, and where it is at risk

"Why does it search GitLab and not GitHub?"

I had asked for GitLab search, so GitLab search is what I got. Then I ran the app on my own phone and looked for rails, elixir, omarchy and typescript-go. Lots of results. Not the ones I wanted. The first hit didn't even have my search term in its name, and after a few tries GitLab told my IP address to come back later.

So, the same night: GitHub became the default, with GitLab (gitlab.com or a company's server) one tap away. Results are ordered by how well the name matches, and only then by stars:

/// 0 the name is the query, 1 it starts with it, 2 it contains it, 3 only
/// the owner or group does, 4 neither (a match in the description).
public static func score(_ repository: RemoteRepository, for query: String) -> Int

The search waits until you stop typing and remembers what it already asked, because a visitor without a token gets ten searches a minute from GitHub. When the limit does hit, the app says when it ends.

Adding gemini-cli: the download, then only the index

Refresh came from using it, too. Swipe a repository to the right. If the download was kept, only what's new is fetched. If not, the app downloads again next to the old index and swaps them when the new one is ready, so the repository stays readable the whole time.

What broke

The app that died without a word. The first download test ended with the whole process killed by signal 13. When the other side closes a connection first, the next write raises SIGPIPE. A Rust program ignores that from the start. An app that merely links a Rust library does not, and the system ends it. The engine now ignores it for the length of a download, and the write fails with an ordinary error.

The screen that wouldn't push. On the closed phone, tapping a row did nothing. The destination was declared inside a tab, and the navigation around a tab view doesn't see it. It moved up a level, and the detail side of the split view got a navigation stack of its own.

The Remove button that removed first. Marked as destructive, the row slid away before the "are you sure" question was answered. Say no and the row was gone from the screen anyway.

You can't fold a simulator from a script. There is no command for the pose. Claude built the app, launched it and tapped through it in the simulator, then had to ask me to unfold the phone. I folded, it looked, we went on. The cramped overview above was found that way.

Jitsanity. For the video's first voice track the Mac read "Gitsanity" as one word and pronounced it with a soft G. I asked for a hard one. Claude can't listen to audio, so it checked by running the track through a speech-to-text model, which wrote down "Jitsanity". Written as "Git Sanity", the voice gets it right.

What it took

About 2,700 lines of Swift for the phone app, plus six files it shares with the Mac app as they are: the engine client, the charts, the palette, the formatting. On the engine side, 310 lines of Rust for downloading and updating and 91 for the bridge. The engine is wrapped as one XCFramework with three slices: the Mac, the iPhone and the simulator.

There are 28 tests for the phone's side: what GitHub and GitLab answer, the ranking, a real download through the engine from a local repository, index-only and kept downloads, failure, restart, refresh.

The first prototype was committed at 11:57pm on a Tuesday. By 12:56am it had been used by touch, unfolded, half folded, run on my real iPhone Duo, had its search rebuilt and gained refresh. The next evening went to making the engine side fit to be public. As with the last three Gitsanity posts, I didn't type the code. I said what I wanted, held the phone, and sent back what was wrong.

Will it ship?

I don't know. I haven't decided whether to put it on the App Store, and I don't know whether Apple would approve it. Everything in it is an official API, the split view, the arrangement view, the standard bars, so I assume they would.

What I will do is open source the app, once it has had a bit more cleanup. The engine already is, and the download feature is in a pull request there now.

What's not there yet

  • Access tokens are untested. There's a field in Settings, stored in the Keychain, for private repositories and higher search limits. I haven't tried it against a real account.
  • Big repositories on a real phone. Swift's 1.5 GB was read in the simulator, with a Mac's memory behind it. The Linux kernel on a phone is an experiment I haven't run.
  • Background downloads. I haven't checked what happens to a download when the app leaves the screen.
  • The inner display in portrait, and the other ways an iPhone Duo can stand, haven't been looked at. Closed, open flat in landscape and half folded have.
  • No Ask, no Lens, no releases. The Mac app has them. The phone has five screens.
  • An app icon.

If you'd use this, or you think nobody would, I'd like to hear it either way. That's the part I can't work out by folding a phone.

Folded shut again, on the repository that was just added


Daniel Wanja is a developer and founder of Nouvelles Solutions, Inc. When not rewriting his own apps, he's unfolding his phone to see what the Zed team did this week.