Skip to content

Commit

Permalink
format fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bummoblizard committed Aug 13, 2023
1 parent d8d170f commit b200777
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 77 deletions.
22 changes: 13 additions & 9 deletions CodeApp/Containers/MainScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -268,16 +268,20 @@ private struct MainView: View {

changeLogLastReadVersion = appVersion
}

.alert(alertManager.title, isPresented: $alertManager.isShowingAlert, actions: {
alertManager.alertContent
}, message: {
if let message = alertManager.message {
Text(message)
}else {
EmptyView()

.alert(
alertManager.title, isPresented: $alertManager.isShowingAlert,
actions: {
alertManager.alertContent
},
message: {
if let message = alertManager.message {
Text(message)
} else {
EmptyView()
}
}
})
)
.fullScreenCover(isPresented: $safariManager.showsSafari) {
if let url = safariManager.urlToVisit {
SafariView(url: url)
Expand Down
18 changes: 10 additions & 8 deletions CodeApp/Containers/SourceControlContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct SourceControlContainer: View {
App.notificationManager.showInformationMessage(
"source_control.repository_initialized")
App.git_status()
}catch {
} catch {
App.notificationManager.showErrorMessage(
error.localizedDescription
)
Expand Down Expand Up @@ -70,10 +70,11 @@ struct SourceControlContainer: View {

App.notificationManager.postProgressNotification(
title: "source_control.pushing_to_remote", progress: progress)

do {
let currentBranch = try await serviceProvider.currentBranch()
try await serviceProvider.push(branch: currentBranch, remote: remote, progress: progress)
try await serviceProvider.push(
branch: currentBranch, remote: remote, progress: progress)
App.notificationManager.showInformationMessage(
"source_control.push_succeeded")
App.git_status()
Expand All @@ -84,7 +85,8 @@ struct SourceControlContainer: View {
title:
"errors.source_control.authentication_failed",
level: .error,
primary: { showsPrompt = true }, primaryTitle: "common.configure", source: "source_control.title")
primary: { showsPrompt = true }, primaryTitle: "common.configure",
source: "source_control.title")
} else {
App.notificationManager.showErrorMessage(
error.localizedDescription)
Expand Down Expand Up @@ -173,7 +175,7 @@ struct SourceControlContainer: View {
primary: {
App.loadFolder(url: dirURL)
}, primaryTitle: "common.open_folder", source: repo)
}catch {
} catch {
let error = error as NSError
if error.code == LibGit2ErrorClass._GIT_ERROR_HTTP {
App.notificationManager.postActionNotification(
Expand Down Expand Up @@ -205,7 +207,7 @@ struct SourceControlContainer: View {
throw error
}
}

}

func onRevert(urlString: String, confirm: Bool = false) async throws {
Expand Down Expand Up @@ -246,13 +248,13 @@ struct SourceControlContainer: View {
}
return
}

do {
let previousContent = try await serviceProvider.previous(path: fileURL.absoluteString)
try previousContent.write(to: fileURL, atomically: true, encoding: .utf8)
App.git_status()
App.notificationManager.showInformationMessage("source_control.revert_succeeded")
}catch {
} catch {
App.notificationManager.showErrorMessage(error.localizedDescription)
throw error
}
Expand Down
23 changes: 13 additions & 10 deletions CodeApp/Managers/BottomBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// Created by Ken Chung on 1/7/2021.
//

import SwiftUI
import SwiftGit2
import SwiftUI

struct BottomBar: View {

Expand All @@ -30,21 +30,21 @@ struct BottomBar: View {
do {
try await gitServiceProvider.checkout(oid: destination.reference.oid)
App.notificationManager.showInformationMessage("Checkout succeeded")
}catch {
} catch {
App.notificationManager.showErrorMessage(error.localizedDescription)
throw error
}
}

func iconNameForReferenceType(_ reference: ReferenceType) -> String {
if reference is TagReference {
return "tag"
}else if let reference = reference as? Branch {
} else if let reference = reference as? Branch {
return (reference.isRemote ? "cloud" : "arrow.triangle.branch")
}
return "circle"
}

var body: some View {
ZStack(alignment: .center) {
Color.init(id: "statusBar.background").frame(maxHeight: 20)
Expand All @@ -69,13 +69,14 @@ struct BottomBar: View {
},
onSelect: { destination in
if !App.gitTracks.isEmpty {

App.alertManager.showAlert(
title: "Git checkout: Uncommitted Changes",
message: "Uncommited changes will be lost. Do you wish to proceed?",
content: AnyView (
message:
"Uncommited changes will be lost. Do you wish to proceed?",
content: AnyView(
Group {
Button("Checkout", role: .destructive){
Button("Checkout", role: .destructive) {
Task {
try await checkout(destination: destination)
}
Expand All @@ -89,7 +90,9 @@ struct BottomBar: View {
try await checkout(destination: destination)
}
}
}, title: App.branch, iconName: "arrow.triangle.branch", menuTitle: "source_control.checkout.select_branch_or_tag")
}, title: App.branch, iconName: "arrow.triangle.branch",
menuTitle: "source_control.checkout.select_branch_or_tag"
)
.fixedSize(horizontal: true, vertical: false)
.frame(height: 20)

Expand Down
45 changes: 25 additions & 20 deletions CodeApp/Managers/FileSystem/Local/LocalGitServiceProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,17 @@ class LocalGitServiceProvider: GitServiceProvider {
let repository = try self.checkedRepository()
let ref = try repository.HEAD().get()
guard let branch = ref as? Branch,
let branchName = branch.shortName
let branchName = branch.shortName
else {
throw NSError(descriptionKey: "Git is in detached mode")
}
let remoteBranch = try repository.remoteBranch(named: "\(remote?.name ?? "origin")/\(branchName)").get()
let remoteBranch = try repository.remoteBranch(
named: "\(remote?.name ?? "origin")/\(branchName)"
).get()
return try repository.aheadBehind(local: ref.oid, upstream: remoteBranch.oid).get()
}
}

func status() async throws -> [StatusEntry] {
return try await WorkerQueueTask {
let repository = try self.checkedRepository()
Expand All @@ -196,7 +198,7 @@ class LocalGitServiceProvider: GitServiceProvider {
]).get()
}
}

func createRepository() async throws {
try await WorkerQueueTask {
guard !self.hasRepository else {
Expand Down Expand Up @@ -233,7 +235,7 @@ class LocalGitServiceProvider: GitServiceProvider {
fetchProgress: fetchProgressBlock
).get()
} else {
_ = try Repository.clone(
_ = try Repository.clone(
from: from,
to: to,
checkoutProgress: checkoutProgressBlock,
Expand Down Expand Up @@ -264,7 +266,7 @@ class LocalGitServiceProvider: GitServiceProvider {
self.contentCache.removeAllObjects()
}
}

func unstage(paths: [String]) async throws {
try await WorkerQueueTask {
let repository = try self.checkedRepository()
Expand Down Expand Up @@ -298,21 +300,21 @@ class LocalGitServiceProvider: GitServiceProvider {
}
}
}

func remotes() async throws -> [Remote] {
return try await WorkerQueueTask {
let repository = try self.checkedRepository()
return try repository.allRemotes().get()
}
}

func currentBranch() async throws -> Branch {
try await WorkerQueueTask {
let repository = try self.checkedRepository()
let head = try repository.HEAD().get()
if let branch = head as? Branch {
return branch
}else {
} else {
throw NSError(descriptionKey: "Repository is in detached mode")
}
}
Expand All @@ -322,7 +324,9 @@ class LocalGitServiceProvider: GitServiceProvider {
try await WorkerQueueTask {
let repository = try self.checkedRepository()
let credentials = try self.checkedCredentials()
try repository.push(credentials: credentials, branch: branch.longName, remoteName: to.name){ current, total in
try repository.push(
credentials: credentials, branch: branch.longName, remoteName: to.name
) { current, total in
DispatchQueue.main.async {
progress?.totalUnitCount = Int64(current)
progress?.completedUnitCount = Int64(total)
Expand All @@ -338,46 +342,47 @@ class LocalGitServiceProvider: GitServiceProvider {
self.contentCache.removeAllObjects()
}
}

func localBranches() async throws -> [Branch] {
return try await WorkerQueueTask{
return try await WorkerQueueTask {
let repository = try self.checkedRepository()
return try repository.localBranches().get()
}
}

func remoteBranches() async throws -> [Branch] {
return try await WorkerQueueTask{
return try await WorkerQueueTask {
let repository = try self.checkedRepository()
return try repository.remoteBranches().get()
}
}

func tags() async throws -> [TagReference] {
return try await WorkerQueueTask{
return try await WorkerQueueTask {
let repository = try self.checkedRepository()
return try repository.allTags().get()
}
}

/// Returns the OID of the path at the current HEAD
private func fileOidAtPathForLastCommit(path: String) throws -> OID {
let repository = try self.checkedRepository()
let entries = try repository.status(options: [.includeUnmodified]).get()
for entry in entries {
if let oldFilePath = entry.headToIndex?.oldFile?.path,
path == oldFilePath,
let oid = entry.headToIndex?.oldFile?.oid {
path == oldFilePath,
let oid = entry.headToIndex?.oldFile?.oid
{
return oid
}
}
throw NSError(descriptionKey: "Unable to locate OID for \(path)")
}

func previous(path: String) async throws -> String {
return try await WorkerQueueTask {
let repository = try self.checkedRepository()

if let cached = self.contentCache.object(forKey: path as NSString) {
return (cached as String)
}
Expand All @@ -386,7 +391,7 @@ class LocalGitServiceProvider: GitServiceProvider {

let oid = try self.fileOidAtPathForLastCommit(path: path)
let blob = try repository.blob(oid).get()

guard let content = String(data: blob.data, encoding: .utf8) else {
throw NSError(descriptionKey: "Unable to decode data")
}
Expand Down
Loading

0 comments on commit b200777

Please sign in to comment.