Repository: CodeEditApp/CodeEdit
File: CodeEdit/Features/Git/SourceControlManager.swift (Swift)

Code before:

    /// All branches, local and remote
    @Published var branches: [GitBranch] = []

    /// All remotes
    @Published var remotes: [GitRemote] = []

    /// All stash ebtrues
    @Published var stashEntries: [GitStashEntry] = []

    /// Number of unsynced commits with remote in current branch
    @Published var numberOfUnsyncedCommits: (ahead: Int, behind: Int) = (ahead: 0, behind: 0)

    @Published var isGitRepository: Bool = false

    var orderedLocalBranches: [GitBranch] {
        var orderedBranches: [GitBranch] = []
        if let currentBranch {
            orderedBranches.append(currentBranch)
        }
        let othersBranch = branches
            .filter { $0.isLocal && $0.name != currentBranch?.name }
            .sorted { $0.name < $1.name }
        orderedBranches.append(contentsOf: othersBranch)
        return orderedBranches
    }

    init(
        workspaceURL: URL,
        editorManager: EditorManager
    ) {
        self.workspaceURL = workspaceURL
        self.editorManager = editorManager
        gitClient = GitClient(directoryURL: workspaceURL, shellClient: currentWorld.shellClient)
    }

    /// Refresh all changed files and refresh status in file manager
    func refreshAllChangedFiles() async {
        do {
            var fileDictionary = [URL: CEWorkspaceFile]()

            // Process changed files
            for item in try await gitClient.getChangedFiles() {
                fileDictionary[item.fileLink] = CEWorkspaceFile(
                    url: item.fileLink,
                    changeType: item.changeType,
                    staged: false
                )
            }

            // Update staged status

Review comment (suggestion):
```suggestion
  var orderedLocalBranches: [GitBranch] {
    var orderedBranches: [GitBranch] = [currentBranch].compactMap { $0 }
    let otherBranches = branches.filter { $0.isLocal && $0 != currentBranch }
                               .sorted { $0.name < $1.name }
    orderedBranches.append(contentsOf: otherBranches)
    return orderedBranches
}
```
I reckon this could do with a bit of improvement.

Code after:

    /// All branches, local and remote
    @Published var branches: [GitBranch] = []

    /// All remotes
    @Published var remotes: [GitRemote] = []

    /// All stash ebtrues
    @Published var stashEntries: [GitStashEntry] = []

    /// Number of unsynced commits with remote in current branch
    @Published var numberOfUnsyncedCommits: (ahead: Int, behind: Int) = (ahead: 0, behind: 0)

    @Published var isGitRepository: Bool = false

    var orderedLocalBranches: [GitBranch] {
        var orderedBranches: [GitBranch] = [currentBranch].compactMap { $0 }
        let otherBranches = branches.filter { $0.isLocal && $0 != currentBranch }
            .sorted { $0.name.lowercased() < $1.name.lowercased() }
        orderedBranches.append(contentsOf: otherBranches)
        return orderedBranches
    }

    init(
        workspaceURL: URL,
        editorManager: EditorManager
    ) {
        self.workspaceURL = workspaceURL
        self.editorManager = editorManager
        gitClient = GitClient(directoryURL: workspaceURL, shellClient: currentWorld.shellClient)
    }

    /// Refresh all changed files and refresh status in file manager
    func refreshAllChangedFiles() async {
        do {
            var fileDictionary = [URL: CEWorkspaceFile]()

            // Process changed files
            for item in try await gitClient.getChangedFiles() {
                fileDictionary[item.fileLink] = CEWorkspaceFile(
                    url: item.fileLink,
                    changeType: item.changeType,
                    staged: false
                )
            }

            // Update staged status
            for item in try await gitClient.getStagedFiles() {
                fileDictionary[item.fileLink]?.staged = true
            }