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

Source Control Settings #1926

Merged
merged 30 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
89ccc14
Hiding source control navigator when source control is disabled in Se…
austincondiff Oct 29, 2024
78b8184
Hiding History Inspector when source control is disabled in Settings.
austincondiff Oct 29, 2024
e58ab76
Hiding Source Control menu when source control is disabled in Settings.
austincondiff Oct 29, 2024
7adc787
If enableSourceControl or refreshStatusLocally setting is false then …
austincondiff Oct 29, 2024
5eb0f7f
Hiding branch picker in the toolbar when source control is disabled i…
austincondiff Oct 29, 2024
b7c9797
Enabled fetch and refresh server status automatically setting. When d…
austincondiff Oct 31, 2024
409c4ce
Author name, author email, and prefer rebase when pulling settings us…
austincondiff Nov 1, 2024
7ddb5e8
Default branch setting uses the users global git config instead of Co…
austincondiff Nov 1, 2024
ae6ba40
Show merge commits per file log setting now shows merge commits if en…
austincondiff Nov 1, 2024
241ebbd
Fixed swiftlint error
austincondiff Nov 1, 2024
996be19
Added Ignored Files list in source control settings. Refactored searc…
austincondiff Nov 2, 2024
52b03ef
Fixed a small race condition
austincondiff Nov 2, 2024
528fe57
Merge branch 'main' into source-control-settings
austincondiff Nov 2, 2024
90934f2
Added type to hasAppeared variable in SourceControlGitView.
austincondiff Nov 2, 2024
9635fe5
Renamed `enableSourceControl` to `sourceControlIsEnabled`. Added docu…
austincondiff Nov 16, 2024
71ee6c6
Ignored files can be changed while preserving comments and white spac…
austincondiff Nov 25, 2024
dbf88a9
Merge branch 'main' into source-control-settings
austincondiff Nov 25, 2024
23148b3
Fixed SwiftLint errors
austincondiff Nov 25, 2024
eab7301
Ignore pattern reorder fixes
austincondiff Nov 26, 2024
b31e07d
Writing relative url to gitconfig upon adding first pattern
austincondiff Nov 26, 2024
284df2e
Cleaned up unecessary function
austincondiff Nov 26, 2024
dbf0929
Trying to fix test
austincondiff Nov 26, 2024
0565305
Dynamically resolve gitignore file path.
austincondiff Nov 30, 2024
93b0be5
Fixing test
austincondiff Nov 30, 2024
464bdea
Added source control settings header. Moved feature icon into new vie…
austincondiff Dec 2, 2024
24658a2
Moved tabs below source control toggle
austincondiff Dec 3, 2024
38cd1f0
Fixed PR issue
austincondiff Dec 4, 2024
35be9a9
PR issues, added documentation
austincondiff Dec 8, 2024
97bbefb
Marked IgnorePatternModel with @MainActor. More documentation. Refact…
austincondiff Dec 8, 2024
a446a18
Adding main actor to savePatterns function in IgnorePatternModel per …
austincondiff Dec 13, 2024
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
8 changes: 8 additions & 0 deletions CodeEdit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,7 @@
B67DB0F62AFC2A7A002DC647 /* FindNavigatorToolbarBottom.swift in Sources */ = {isa = PBXBuildFile; fileRef = B67DB0F52AFC2A7A002DC647 /* FindNavigatorToolbarBottom.swift */; };
B67DB0F92AFDF638002DC647 /* IconButtonStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = B67DB0F82AFDF638002DC647 /* IconButtonStyle.swift */; };
B67DB0FC2AFDF71F002DC647 /* IconToggleStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = B67DB0FB2AFDF71F002DC647 /* IconToggleStyle.swift */; };
B67DBB882CD51C55007F4F18 /* Limiter.swift in Sources */ = {isa = PBXBuildFile; fileRef = B67DBB872CD51C51007F4F18 /* Limiter.swift */; };
B68108042C60287F008B27C1 /* StartTaskToolbarButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = B68108032C60287F008B27C1 /* StartTaskToolbarButton.swift */; };
B685DE7929CC9CCD002860C8 /* StatusBarIcon.swift in Sources */ = {isa = PBXBuildFile; fileRef = B685DE7829CC9CCD002860C8 /* StatusBarIcon.swift */; };
B6966A282C2F683300259C2D /* SourceControlPullView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6966A272C2F683300259C2D /* SourceControlPullView.swift */; };
Expand Down Expand Up @@ -585,6 +586,7 @@
B6CFD8112C20A8EE00E63F1A /* NSFont+WithWeight.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6CFD8102C20A8EE00E63F1A /* NSFont+WithWeight.swift */; };
B6D7EA592971078500301FAC /* InspectorSection.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6D7EA582971078500301FAC /* InspectorSection.swift */; };
B6D7EA5C297107DD00301FAC /* InspectorField.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6D7EA5B297107DD00301FAC /* InspectorField.swift */; };
B6E38E022CD3E63A00F4E65A /* GitConfigClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6E38E012CD3E62E00F4E65A /* GitConfigClient.swift */; };
B6E41C7029DD157F0088F9F4 /* AccountsSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6E41C6F29DD157F0088F9F4 /* AccountsSettingsView.swift */; };
B6E41C7429DD40010088F9F4 /* View+HideSidebarToggle.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6E41C7329DD40010088F9F4 /* View+HideSidebarToggle.swift */; };
B6E41C7929DE02800088F9F4 /* AccountSelectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6E41C7829DE02800088F9F4 /* AccountSelectionView.swift */; };
Expand Down Expand Up @@ -1217,6 +1219,7 @@
B67DB0F52AFC2A7A002DC647 /* FindNavigatorToolbarBottom.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FindNavigatorToolbarBottom.swift; sourceTree = "<group>"; };
B67DB0F82AFDF638002DC647 /* IconButtonStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IconButtonStyle.swift; sourceTree = "<group>"; };
B67DB0FB2AFDF71F002DC647 /* IconToggleStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IconToggleStyle.swift; sourceTree = "<group>"; };
B67DBB872CD51C51007F4F18 /* Limiter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Limiter.swift; sourceTree = "<group>"; };
B68108032C60287F008B27C1 /* StartTaskToolbarButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StartTaskToolbarButton.swift; sourceTree = "<group>"; };
B685DE7829CC9CCD002860C8 /* StatusBarIcon.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusBarIcon.swift; sourceTree = "<group>"; };
B6966A272C2F683300259C2D /* SourceControlPullView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SourceControlPullView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1248,6 +1251,7 @@
B6CFD8102C20A8EE00E63F1A /* NSFont+WithWeight.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSFont+WithWeight.swift"; sourceTree = "<group>"; };
B6D7EA582971078500301FAC /* InspectorSection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectorSection.swift; sourceTree = "<group>"; };
B6D7EA5B297107DD00301FAC /* InspectorField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectorField.swift; sourceTree = "<group>"; };
B6E38E012CD3E62E00F4E65A /* GitConfigClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GitConfigClient.swift; sourceTree = "<group>"; };
B6E41C6F29DD157F0088F9F4 /* AccountsSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountsSettingsView.swift; sourceTree = "<group>"; };
B6E41C7329DD40010088F9F4 /* View+HideSidebarToggle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+HideSidebarToggle.swift"; sourceTree = "<group>"; };
B6E41C7829DE02800088F9F4 /* AccountSelectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountSelectionView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2252,6 +2256,7 @@
isa = PBXGroup;
children = (
58A5DF7F29325B5A00D1BD5D /* GitClient.swift */,
B6E38E012CD3E62E00F4E65A /* GitConfigClient.swift */,
04BA7C182AE2D7C600584E1C /* GitClient+Branches.swift */,
04BA7C1D2AE2D8A000584E1C /* GitClient+Clone.swift */,
04BA7C1B2AE2D84100584E1C /* GitClient+Commit.swift */,
Expand Down Expand Up @@ -2435,6 +2440,7 @@
5831E3C92933E83400D5A6D2 /* Protocols */,
5875680E29316BDC00C965A3 /* ShellClient */,
6C5C891A2A3F736500A94FE1 /* FocusedValues.swift */,
B67DBB872CD51C51007F4F18 /* Limiter.swift */,
);
path = Utils;
sourceTree = "<group>";
Expand Down Expand Up @@ -4025,6 +4031,7 @@
58798233292E30B90085B254 /* FeedbackToolbar.swift in Sources */,
6CC17B5B2C44258700834E2C /* WindowControllerPropertyWrapper.swift in Sources */,
587B9E6829301D8F00AC7927 /* GitLabAccountModel.swift in Sources */,
B67DBB882CD51C55007F4F18 /* Limiter.swift in Sources */,
5878DAA7291AE76700DD95A3 /* OpenQuicklyViewModel.swift in Sources */,
6CFF967429BEBCC300182D6F /* FindCommands.swift in Sources */,
587B9E6529301D8F00AC7927 /* GitLabGroupAccess.swift in Sources */,
Expand Down Expand Up @@ -4241,6 +4248,7 @@
581550D429FBD37D00684881 /* ProjectNavigatorToolbarBottom.swift in Sources */,
66AF6CE72BF17FFB00D83C9D /* UpdateStatusBarInfo.swift in Sources */,
587B9E7E29301D8F00AC7927 /* GitHubGistRouter.swift in Sources */,
B6E38E022CD3E63A00F4E65A /* GitConfigClient.swift in Sources */,
B6AB09A52AAAC00F0003A3A6 /* EditorTabBarTrailingAccessories.swift in Sources */,
04BA7C0B2AE2A2D100584E1C /* GitBranch.swift in Sources */,
6CAAF69229BCC71C00A1F48A /* (null) in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extension CEWorkspaceFileManager {
// Can be ignored for now, these I think not related to tree changes
continue
case .rootChanged:
// TODO: Handle workspace root changing.
// TODO: #1880 - Handle workspace root changing.
continue
case .itemCreated, .itemCloned, .itemRemoved, .itemRenamed:
for fileItem in fileItems {
Expand All @@ -48,7 +48,10 @@ extension CEWorkspaceFileManager {
self.notifyObservers(updatedItems: files)
}

self.handleGitEvents(events: events)
if Settings.shared.preferences.sourceControl.general.enableSourceControl &&
Settings.shared.preferences.sourceControl.general.refreshStatusLocally {
self.handleGitEvents(events: events)
}
}
}

Expand Down
12 changes: 8 additions & 4 deletions CodeEdit/Features/CodeEditUI/Views/ToolbarBranchPicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ struct ToolbarBranchPicker: View {
isHovering = active
}
.onReceive(NotificationCenter.default.publisher(for: NSApplication.didBecomeActiveNotification)) { (_) in
Task {
await sourceControlManager?.refreshCurrentBranch()
if self.currentBranch != nil {
Task {
await sourceControlManager?.refreshCurrentBranch()
}
}
}
.onReceive(
Expand All @@ -82,8 +84,10 @@ struct ToolbarBranchPicker: View {
self.currentBranch = branch
}
.task {
await self.sourceControlManager?.refreshCurrentBranch()
await self.sourceControlManager?.refreshBranches()
if Settings.shared.preferences.sourceControl.general.enableSourceControl {
await self.sourceControlManager?.refreshCurrentBranch()
await self.sourceControlManager?.refreshBranches()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ final class HistoryInspectorModel: ObservableObject {
do {
let commitHistory = try await sourceControlManager
.gitClient
.getCommitHistory(maxCount: 40, fileLocalPath: fileURL)
.getCommitHistory(
maxCount: 40,
fileLocalPath: fileURL,
showMergeCommits: Settings.shared.preferences.sourceControl.git.showMergeCommitsPerFileLog
)
await setCommitHistory(commitHistory)
} catch {
await setCommitHistory([])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import SwiftUI

struct HistoryInspectorView: View {
@AppSettings(\.sourceControl.git.showMergeCommitsPerFileLog)
var showMergeCommitsPerFileLog

@EnvironmentObject private var workspace: WorkspaceDocument

@EnvironmentObject private var editorManager: EditorManager
Expand Down Expand Up @@ -60,5 +63,10 @@ struct HistoryInspectorView: View {
await model.setWorkspace(sourceControlManager: workspace.sourceControlManager)
await model.setFile(url: editorManager.activeEditor.selectedTab?.file.url.path)
}
.onChange(of: showMergeCommitsPerFileLog) { _ in
Task {
await model.updateCommitHistory()
}
}
}
}
47 changes: 27 additions & 20 deletions CodeEdit/Features/InspectorArea/Views/InspectorAreaView.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
//
// InspectorAreaView.swift
// CodeEdit
//
// Created by Austin Condiff on 3/21/22.
//

import SwiftUI

struct InspectorAreaView: View {
Expand All @@ -15,26 +8,17 @@ struct InspectorAreaView: View {

@EnvironmentObject private var editorManager: EditorManager

@AppSettings(\.sourceControl.general.enableSourceControl)
private var enableSourceControl: Bool

@AppSettings(\.general.inspectorTabBarPosition)
var sidebarPosition: SettingsData.SidebarTabBarPosition

@State private var selection: InspectorTab? = .file

init(viewModel: InspectorAreaViewModel) {
self.viewModel = viewModel

viewModel.tabItems = [.file, .gitHistory]
viewModel.tabItems += extensionManager
.extensions
.map { ext in
ext.availableFeatures.compactMap {
if case .sidebarItem(let data) = $0, data.kind == .inspector {
return InspectorTab.uiExtension(endpoint: ext.endpoint, data: data)
}
return nil
}
}
.joined()
updateTabItems()
}

func getExtension(_ id: String) -> ExtensionInfo? {
Expand Down Expand Up @@ -73,5 +57,28 @@ struct InspectorAreaView: View {
.formStyle(.grouped)
.accessibilityElement(children: .contain)
.accessibilityLabel("inspector")
.onChange(of: enableSourceControl) { _ in
updateTabItems()
}
}

private func updateTabItems() {
viewModel.tabItems = [.file] +
(enableSourceControl ? [.gitHistory] : []) +
extensionManager
.extensions
.flatMap { ext in
ext.availableFeatures.compactMap {
if case .sidebarItem(let data) = $0, data.kind == .inspector {
return InspectorTab.uiExtension(endpoint: ext.endpoint, data: data)
}
return nil
}
}
if let selectedTab = selection,
!viewModel.tabItems.isEmpty &&
!viewModel.tabItems.contains(selectedTab) {
selection = viewModel.tabItems[0]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ struct SourceControlNavigatorHistoryView: View {
case error(error: Error)
}

@AppSettings(\.sourceControl.git.showMergeCommitsPerFileLog)
var showMergeCommitsPerFileLog

@EnvironmentObject var sourceControlManager: SourceControlManager

@State var commitHistoryStatus: Status = .loading
Expand All @@ -28,7 +31,10 @@ struct SourceControlNavigatorHistoryView: View {
commitHistoryStatus = .loading
let commits = try await sourceControlManager
.gitClient
.getCommitHistory(branchName: sourceControlManager.currentBranch?.name)
.getCommitHistory(
branchName: sourceControlManager.currentBranch?.name,
showMergeCommits: Settings.shared.preferences.sourceControl.git.showMergeCommitsPerFileLog
)
await MainActor.run {
commitHistory = commits
commitHistoryStatus = .ready
Expand Down Expand Up @@ -102,5 +108,10 @@ struct SourceControlNavigatorHistoryView: View {
.task {
await updateCommitHistory()
}
.onChange(of: showMergeCommitsPerFileLog) { _ in
Task {
await updateCommitHistory()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import SwiftUI
struct SourceControlNavigatorView: View {
@EnvironmentObject private var workspace: WorkspaceDocument

@AppSettings(\.sourceControl.general.fetchRefreshServerStatus)
var fetchRefreshServerStatus

var body: some View {
if let sourceControlManager = workspace.workspaceFileManager?.sourceControlManager {
VStack(spacing: 0) {
Expand All @@ -18,7 +21,9 @@ struct SourceControlNavigatorView: View {
.task {
do {
while true {
try await sourceControlManager.fetch()
if fetchRefreshServerStatus {
try await sourceControlManager.fetch()
}
try await Task.sleep(for: .seconds(10))
}
} catch {
Expand Down
41 changes: 28 additions & 13 deletions CodeEdit/Features/NavigatorArea/Views/NavigatorAreaView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,13 @@ struct NavigatorAreaView: View {
@AppSettings(\.general.navigatorTabBarPosition)
var sidebarPosition: SettingsData.SidebarTabBarPosition

@AppSettings(\.sourceControl.general.enableSourceControl)
private var enableSourceControl: Bool

init(workspace: WorkspaceDocument, viewModel: NavigatorSidebarViewModel) {
self.workspace = workspace
self.viewModel = viewModel

viewModel.tabItems = [.project, .sourceControl, .search] +
extensionManager
.extensions
.map { ext in
ext.availableFeatures.compactMap {
if case .sidebarItem(let data) = $0, data.kind == .navigator {
return NavigatorTab.uiExtension(endpoint: ext.endpoint, data: data)
}
return nil
}
}
.joined()
updateTabItems()
}

var body: some View {
Expand Down Expand Up @@ -63,5 +54,29 @@ struct NavigatorAreaView: View {
.environmentObject(workspace)
.accessibilityElement(children: .contain)
.accessibilityLabel("navigator")
.onChange(of: enableSourceControl) { _ in
updateTabItems()
}
}

private func updateTabItems() {
viewModel.tabItems = [.project] +
(enableSourceControl ? [.sourceControl] : []) +
[.search] +
extensionManager
.extensions
.flatMap { ext in
ext.availableFeatures.compactMap {
if case .sidebarItem(let data) = $0, data.kind == .navigator {
return NavigatorTab.uiExtension(endpoint: ext.endpoint, data: data)
}
return nil
}
}
if let selectedTab = viewModel.selectedTab,
!viewModel.tabItems.isEmpty &&
!viewModel.tabItems.contains(selectedTab) {
viewModel.selectedTab = viewModel.tabItems[0]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,23 @@ extension SettingsData {
/// Indicates whether or not the source control is active
var enableSourceControl: Bool = true
/// Indicates whether or not we should include the upstream changes
var refreshStatusLocally: Bool = false
var refreshStatusLocally: Bool = true
/// Indicates whether or not we should include the upstream changes
var fetchRefreshServerStatus: Bool = false
var fetchRefreshServerStatus: Bool = true
/// Indicates whether or not we should include the upstream changes
var addRemoveAutomatically: Bool = false
var addRemoveAutomatically: Bool = true
/// Indicates whether or not we should include the upstream changes
var selectFilesToCommit: Bool = false
var selectFilesToCommit: Bool = true
/// Indicates whether or not to show the source control changes
var showSourceControlChanges: Bool = true
/// Indicates whether or not we should include the upstream
var includeUpstreamChanges: Bool = false
var includeUpstreamChanges: Bool = true
/// Indicates whether or not we should open the reported feedback in the browser
var openFeedbackInBrowser: Bool = true
/// The selected value of the comparison view
var revisionComparisonLayout: RevisionComparisonLayout = .localLeft
/// The selected value of the control navigator
var controlNavigatorOrder: ControlNavigatorOrder = .sortByName
/// The name of the default branch
var defaultBranchName: String = "main"
/// Default initializer
init() {}
/// Explicit decoder init for setting default values when key is not present in `JSON`
Expand Down Expand Up @@ -109,7 +107,6 @@ extension SettingsData {
ControlNavigatorOrder.self,
forKey: .controlNavigatorOrder
) ?? .sortByName
self.defaultBranchName = try container.decodeIfPresent(String.self, forKey: .defaultBranchName) ?? "main"
}
}

Expand All @@ -130,31 +127,18 @@ extension SettingsData {
}

struct SourceControlGit: Codable, Hashable {
/// The author name
var authorName: String = ""
/// The author email
var authorEmail: String = ""
/// Indicates what files should be ignored when committing
var ignoredFiles: [IgnoredFiles] = []
/// Indicates whether we should rebase when pulling commits
var preferRebaseWhenPulling: Bool = false
/// Indicates whether we should show commits per file log
var showMergeCommitsPerFileLog: Bool = false
/// Default initializer
init() {}
/// Explicit decoder init for setting default values when key is not present in `JSON`
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.authorName = try container.decodeIfPresent(String.self, forKey: .authorName) ?? ""
self.authorEmail = try container.decodeIfPresent(String.self, forKey: .authorEmail) ?? ""
self.ignoredFiles = try container.decodeIfPresent(
[IgnoredFiles].self,
forKey: .ignoredFiles
) ?? []
self.preferRebaseWhenPulling = try container.decodeIfPresent(
Bool.self,
forKey: .preferRebaseWhenPulling
) ?? false
self.showMergeCommitsPerFileLog = try container.decodeIfPresent(
Bool.self,
forKey: .showMergeCommitsPerFileLog
Expand Down
Loading
Loading