Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] pull with fast-forward merge #890

Merged
merged 4 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion CodeApp/Containers/SourceControlContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,17 @@ struct SourceControlContainer: View {
}
}

func onPull(branch: Branch, remote: Remote) async throws {
guard let serviceProvider = App.workSpaceStorage.gitServiceProvider else {
throw SourceControlError.gitServiceProviderUnavailable
}

// TODO: Progress, error handling
try await App.notificationManager.withAsyncNotification(title: "source_control.pulling_from_remote") {
try await serviceProvider.pull(branch: branch, Remote: remote)
}
}

var body: some View {
VStack(spacing: 0) {
// InfinityProgressView(enabled: stateManager.gitServiceIsBusy)
Expand All @@ -324,7 +335,8 @@ struct SourceControlContainer: View {
onUnstage: onUnstage,
onRevert: onRevert,
onStage: onStage,
onShowChangesInDiffEditor: onShowChangesInDiffEditor
onShowChangesInDiffEditor: onShowChangesInDiffEditor,
onPull: onPull
)
} else {
SourceControlEmptySection(onInitializeRepository: onInitializeRepository)
Expand Down
2 changes: 2 additions & 0 deletions CodeApp/Localization/de.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,8 @@
"source_control.community_templates" = "Community-Vorlagen";
"source_control.community_templates.description" = "Community-Vorlagen sind Repositories auf GitHub mit dem Tag #codeapp-template. Sie können dies im Einstellungsmenü deaktivieren.";
"source_control.clone" = "Klonen";
"source_control.pull" = "Pull";
"source_control.pulling_from_remote" = "Vom Remote-Server abrufen";

"panel.problems.no_problems_detected" = "keine Probleme im Arbeitsbereich erkannt.";
"panel.execution.press_play_to_execute_code" = "Drücken Sie die Wiedergabetaste, um den Code auszuführen. Die Programmeingabe muss vor der Ausführung ausgefüllt werden.";
Expand Down
4 changes: 3 additions & 1 deletion CodeApp/Localization/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ are licensed under [BSD-3-Clause License](https://en.wikipedia.org/wiki/BSD_lice
"errors.fs.attempting_to_copy_oneself" = "Source has the same path as the parent.";
"errors.fs.already_connecting_to_a_host" = "Already connecting to a host.";
"errors.source_control.authentication_failed" = "Authentication failed: You might need to configure your git credentials.";
"errors.source_control.clone_authentication_failed" = "Authentication failed: Either the repository url is wrong or you need to configure your git credentials.";
"errors.source_control.clone_authentication_failed" = "Authentication failed: Check your credentials configuration.";
"errors.source_control.no_staged_changes" = "There are no staged changes.";
"errors.source_control.empty_commit_message" = "Commit message cannot be empty";
"errors.source_control.invalid_url" = "Invalid URL";
Expand Down Expand Up @@ -347,6 +347,8 @@ are licensed under [BSD-3-Clause License](https://en.wikipedia.org/wiki/BSD_lice
"source_control.community_templates" = "Community Templates";
"source_control.community_templates.description" = "Community Templates are repositories on GitHub with the #codeapp-template tag. You can disable this in the settings menu.";
"source_control.clone" = "Clone";
"source_control.pull" = "Pull";
"source_control.pulling_from_remote" = "Pulling from remote";


"panel.problems.no_problems_detected" = "No problems detected in the workspace.";
Expand Down
2 changes: 2 additions & 0 deletions CodeApp/Localization/ja.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,8 @@
"source_control.community_templates" = "コミュニティ テンプレート";
"source_control.community_templates.description" = "コミュニティ テンプレートは、#codeapp-template タグが付いた GitHub のリポジトリです。 設定メニューでこれを無効にすることができます。";
"source_control.clone" = "クローン";
"source_control.pull" = "プル";
"source_control.pulling_from_remote" = "リモートからプルしています";

"panel.problems.no_problems_detected" = "ワークスペースで問題は検出されませんでした。";
"panel.execution.press_play_to_execute_code" = "実行ボタンを押すとコードが実行されます。プログラムは実行前に入力する必要があります。";
Expand Down
2 changes: 2 additions & 0 deletions CodeApp/Localization/ko.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,8 @@
"source_control.community_templates" = "커뮤니티 템플릿";
"source_control.community_templates.description" = "커뮤니티 템플릿은 #codeapp-template 태그가 있는 GitHub의 리포지토리입니다. 설정 메뉴에서 비활성화할 수 있습니다.";
"source_control.clone" = "복제";
"source_control.pull" = "풀";
"source_control.pulling_from_remote" = "원격 서버에서 풀";

"panel.problems.no_problems_detected" = "작업 공간에서 감지된 문제 없음.";
"panel.execution.press_play_to_execute_code" = "코드를 실행하려면 실행 버튼을 누르십시오. 실행하기 전에 프로그램 입력을 채워야 합니다.";
Expand Down
2 changes: 2 additions & 0 deletions CodeApp/Localization/zh-Hans.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,8 @@
"source_control.community_templates" = "社区模板";
"source_control.community_templates.description" = "社区模板是 GitHub 上带有#codeapp-template 标签的存储库。 您可以在设置菜单中禁用此功能。";
"source_control.clone" = "克隆";
"source_control.pull" = "拉取";
"source_control.pulling_from_remote" = "拉取中";

"panel.problems.no_problems_detected" = "工作区中未检测到问题。";
"panel.execution.press_play_to_execute_code" = "按下播放按钮执行代码。程序输入需要在执行前填写。";
Expand Down
2 changes: 2 additions & 0 deletions CodeApp/Managers/FileSystem/GitServiceProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,6 @@ protocol GitServiceProvider {
completionHandler: @escaping (String) -> Void
)
func remotes() async throws -> [Remote]
func pull(branch: Branch, Remote from: Remote) async throws
func remoteBranches() async throws -> [Branch]
}
42 changes: 42 additions & 0 deletions CodeApp/Managers/FileSystem/Local/LocalGitServiceProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,24 @@ class LocalGitServiceProvider: GitServiceProvider {
}
}

func remoteBranches() async throws -> [Branch] {
guard let repository = self.repository else {
throw NSError(
domain: "", code: 401,
userInfo: [NSLocalizedDescriptionKey: "Repository doesn't exist"])
}
return try await withCheckedThrowingContinuation { continuation in
workerQueue.async {
switch repository.remoteBranches() {
case .success(let branches):
continuation.resume(returning: branches)
case .failure(let error):
continuation.resume(throwing: error)
}
}
}
}

func checkoutDestinations() -> [checkoutDest] {
return branches(isRemote: true) + branches(isRemote: false) + tags()
}
Expand Down Expand Up @@ -973,4 +991,28 @@ class LocalGitServiceProvider: GitServiceProvider {
}
}
}

func pull(branch: Branch, Remote from: Remote) async throws {
guard let repository = self.repository else {
throw NSError(
domain: "", code: 401,
userInfo: [NSLocalizedDescriptionKey: "Repository doesn't exist"])
}
guard let credential = self.credential else {
throw NSError(
domain: "", code: -16,
userInfo: [NSLocalizedDescriptionKey: "Credentials are not configured"])
}

return try await withCheckedThrowingContinuation { continuation in
workerQueue.async {
do {
try repository.pull(branch: branch, from: from, credentials: credential)
continuation.resume()
} catch {
continuation.resume(throwing: error)
}
}
}
}
}
39 changes: 35 additions & 4 deletions CodeApp/Views/SourceControlSection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@ struct SourceControlSection: View {
let onRevert: (String, Bool) async throws -> Void
let onStage: ([String]) throws -> Void
let onShowChangesInDiffEditor: (String) throws -> Void
let onPull: (Branch, Remote) async throws -> Void

var body: some View {
Group {
MainSection(
onCommit: onCommit, onPush: onPush, onFetch: onFetch,
onStageAllChanges: onStageAllChanges)
onCommit: onCommit,
onPush: onPush,
onFetch: onFetch,
onStageAllChanges: onStageAllChanges,
onPull: onPull
)
if !App.indexedResources.isEmpty {
StagedChangesSection(
onUnstage: onUnstage,
Expand All @@ -51,11 +56,13 @@ private struct MainSection: View {

@State var showsIdentitySheet: Bool = false
@State var remotes: [Remote] = []
@State var branches: [Branch] = []

let onCommit: () async throws -> Void
let onPush: (Remote) async throws -> Void
let onFetch: () async throws -> Void
let onStageAllChanges: () throws -> Void
let onPull: (Branch, Remote) async throws -> Void

func onPushButtonTapped(remote: Remote) {
Task {
Expand Down Expand Up @@ -136,6 +143,24 @@ private struct MainSection: View {
Label("Push", systemImage: "square.and.arrow.up")
}

Menu {
ForEach(remotes, id: \.hashValue) { remote in
Menu {
ForEach(branches, id: \.hashValue) { branch in
Button("\(branch.name)") {
Task {
try await onPull(branch, remote)
}
}
}
} label: {
Text("\(remote.name) - \(remote.URL)")
}
}
} label: {
Label("source_control.pull", systemImage: "square.and.arrow.down")
}

Button(action: {
Task {
try await onFetch()
Expand All @@ -161,12 +186,18 @@ private struct MainSection: View {
}
.onAppear {
Task {
self.remotes =
let remotesResult =
(try? await App.workSpaceStorage.gitServiceProvider?
.remotes()) ?? []
let remoteBranchesResult =
(try? await App.workSpaceStorage.gitServiceProvider?.remoteBranches())
?? []
await MainActor.run {
self.remotes = remotesResult
self.branches = remoteBranchesResult
}
}
}

}.sheet(isPresented: $showsIdentitySheet) {
NavigationView {
SourceControlIdentityConfiguration()
Expand Down
Loading