Skip to content

Git push/pull broken for repos whose branch isn't master (iOS, existing repo) #1991

Description

@wizzard0

Describe the bug

Attaching FSNotes iOS (Version 7.3.2 build 337) to a pre-existing git repository whose local branch is not master (mine was default, created by Working Copy;) makes "Add/commit/push" fail with an unhelpful alert:

Git error
The operation couldn't be completed. ("FSNotes_iOS.GitError error 1.")

("error 1" is probably GitError.notFound(ref:) by enum case position.)

The commit itself succeeds — the failure happens in the push/pull ref handling, which assumes master in several places.

To Reproduce

  1. iOS, iCloud Drive disabled for FSNotes (so get仓库Url() uses <folder>/.git — the existing repo).
  2. Attach an external folder that is already a git repo with a single local branch named default (or main).
  3. Configure origin + SSH key in folder Git 设置.
  4. Create a single note with arbitrary text
  5. Tap "Git Add/commit/push".
  6. Progress shows git add .git commit done, then the alert above. Nothing is pushed. Opening the repo in Working Copy shows the commit was created.

Expected behavior

Push/pull should operate on the repository's current HEAD branch, whatever its name.

Probable cause (disclaimer: by Claude)

  1. Project.push() (FSNotesCore/Extensions/Project+Git.swift) selects the branch as names.first of all local branches instead of resolving HEAD. With multiple branches, libgit2 enumerates refs alphabetically, so the pushed branch is effectively "whichever sorts first" — e.g. default wins over master even if HEAD is master.

  2. Remote.push(local:remote:) (FSNotesCore/Git/remote/Remote.swift, ~L149) is called with remote: nil, producing refspec local.name:local.name. Fine per se, but combined with (1) the user has no control over what gets pushed.

  3. Project.pullPush() (FSNotesCore/Extensions/Project+Git.swift, ~L463) has a recovery path that only handles catch GitError.notFound(ref) when ref == "refs/heads/master". Any other branch name falls through to the generic error alert.

Suggested fix (disclaimer: by Claude)

Resolve the branch from git_repository_head() (short name) everywhere instead of names.first / hardcoded "master", and use it in both the push refspec and the notFound recovery check. That makes FSNotes work with main, master, and anything else without behavior changes for existing users.

FSNotes version

7.3.2 build 337 (App Store), iOS

Workaround

Workaround that got me unblocked: creating a fresh repo where FSNotes creates master itself makes everything work, which supports the diagnosis above.

Thanks

Also, thanks for the attention to the application performance!

It's the first iOS app that is not unbearably slow with my stash of Markdown files!

Metadata

Metadata

Assignees

No one assigned

    标签

    No labels
    No labels

    项目

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions