Skip to content

Commit a231637

Browse files
Additional Source Control Functionality (#1785)
### Description We are improving upon existing source control functionality by doing the following... - Added push functionality and sheet. - Added pull functionality and sheet. - Added manual fetch functionality and fetching sheet. - Reorganized source control files in project - Renamed Features/Git to Features/SourceControl - Moved sheet views into it from the Source Control Navigator - Moved models out of Client - Moved the sync view above commit form in source control changes navigator. - Refreshing remotes cache after adding a remote. - Moved push and pull state variables into the source control manager. - Added a confirm branch switch sheet. - Stashing changes if changes exist when attempting to pull or switch branches. - Setting remote for push and pull after adding a remote. - Added warning alerts if uncommitted changes are not present - It is now possible to switch to a remote branch and create a new branch from a remote branch. - Disabling rename branch for remote branches. ### Testing Note to reviewers... Please pull down and test this in addition to reviewing the code. Once you have this pulled down... In a terminal run... ``` mkdir test.git cd test.git git init --bare ``` Then add the remote in CodeEdit by 1. going to the Source Control Navigator 2. If not already click Initiate to start a git repo 3. go to the Repositories tab 4. Right click Remotes and click Add existing remote... 5. Give the remote a name like "test" (the first remote will be "origin") and enter the path to test.git 7. You can now make changes, commit, and push via the Changes tab in the Source Control Navigator 6. You can set up additional projects by repeating steps 1-5 so you can make changes elsewhere and test pull functionality. 7. You can create additional remotes as well to test managing a project with multiple remotes, pushing and pulling from them, etc. ### Checklist - [x] Add push logic - [x] Add pull logic - [x] Add push sheet - [x] Add pull sheet - [x] Add centralized sheets view - [x] Rename Features/Git to Features/SourceControl - [x] Move sheet views into Features/SourceControl - [x] Add "Source Control" menu - [x] Add remote from push and pull sheets - [x] Set new remote in push or pull sheet after one is added - [x] Stash changes if attempting to pull or switch branches and changes exist - [x] Add fetch to the menu and display fetching sheet while fetching - [x] Add confirm branch switch sheet - [x] Add warning alerts if uncommitted changes are not present --- - [x] I read and understood the [contributing guide](https://github.com/CodeEditApp/CodeEdit/blob/main/CONTRIBUTING.md) as well as the [code of conduct](https://github.com/CodeEditApp/CodeEdit/blob/main/CODE_OF_CONDUCT.md) - [x] The issues this PR addresses are related to each other - [x] My changes generate no new warnings - [x] My code builds and runs on my machine - [x] My changes are all related to the related issue above - [x] I documented my code ### Screenshots <img width="598" alt="image" src="https://github.com/CodeEditApp/CodeEdit/assets/806104/e599cb12-0772-4a6e-abca-b5f9af7fa74a"> <img width="598" alt="image" src="https://github.com/CodeEditApp/CodeEdit/assets/806104/eca3d546-d38c-4787-89ed-9930220fd4e4"> <img width="598" alt="image" src="https://github.com/CodeEditApp/CodeEdit/assets/806104/20a5c002-5fff-4920-8211-8333fce56f6b"> <img width="598" alt="image" src="https://github.com/CodeEditApp/CodeEdit/assets/806104/6e80c67b-5356-4cf7-82b7-1ad95a13e05b"> <img width="342" alt="image" src="https://github.com/CodeEditApp/CodeEdit/assets/806104/0e55f5f8-f71b-4e30-bc05-d80a5796360e"> <img width="712" alt="image" src="https://github.com/CodeEditApp/CodeEdit/assets/806104/00c61863-5cb4-409b-b2d6-40098db5c57e"> ### Todos discovered - Reload source editor contents when file is changed externally - Handle source control errors better and show necessary errors to user - Handle rebase and merge conflict flow in UI - ~~Display loading indicator when pushing or pulling~~ Be able to cancel push or pull while in progress - Display loading indicator when pulling from stash sheet - Write tests for source control features ### Commits * Getting tracked branch and changing source control navigator UI if there is not a tracked branch. * Added push and pull sheet. Renamed Features/Git to Features/SourceControl and moved sheet views into it from the Source Control Navigator. * Fixed dismiss on submit. Changed sheet width * Changed navigator tab label * Removed print statement * Fixed commit branch and tag design in history tab * `SourceControlCommands` Impl * Now that we can access source control features outside the navigator, we need to refresh git data right away rather than on navigator view init. * Added the ability to add existing remotes from the push or pull sheet and source control menu. * Added the ability to add existing remotes from the push or pull sheet and source control menu. * Added ability to fetch changes from the menu * Split up source control manager file to resolve SwiftLint error * SwiftLint fixes * Resolved PR issues * Moved the sync view above commit form in source control changes navigator. Refereshing remotes cache after adding a remote. Moved push and pull state variables into the source control manager. Stashing changes if changes exist when attempting a pull. Setting remote for push and pull after adding a remote. Renamed scm variables to sourceControlManager for clarity. * SwiftLint error fixes * Separated "Apply stash after operation" field into it's own section in stash sheet * Reset remote and branch after stash * Moved functions below body in source control views * Recfactored pull function arguments * Added more detailed comment for SourceControlManager. Moved Git models. * Made setUpstream default to false in the push function * When switching branches, we now have the user confirm. We also check for changes and if there are changes we prompt the user to stash changes before switching branches. * Added warning alerts if uncommited changes are not present * Added minimum width to buttons in source control sheets * Not showing sync view if there are no remotes. * Formatting branch and remote names in the add sheet. * Fixed push PR issue * It is now possible to switch to a remote branch and create a new branch from a remote branch. We are now disabling rename branch for remote branches. * Removed redundant nil * Added loading indicators in push and pull sheets * Fixed SwiftLint errors * Fixed SwiftLint error * Added documentation to submit functions in push and pull views * Renamed a few files that were previously moved and added documentation to new branch and rename branch views --------- Co-authored-by: Khan Winter <35942988+thecoolwinter@users.noreply.github.com>
1 parent 5eba707 commit a231637

File tree

117 files changed

+1516
-513
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+1516
-513
lines changed

CodeEdit.xcodeproj/project.pbxproj

Lines changed: 83 additions & 23 deletions
Large diffs are not rendered by default.

CodeEdit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CodeEdit/Features/CodeEditUI/Views/CEContentUnavailableView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ struct CEContentUnavailableView<Actions: View>: View {
3939
if description != nil {
4040
Text(description ?? "")
4141
.font(.system(size: 10))
42+
.multilineTextAlignment(.center)
4243
}
4344
}
4445
if let actionsView = actions {

CodeEdit/Features/CodeEditUI/Views/KeyValueTable.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private struct NewListTableItemView: View {
9090
.padding(.horizontal, 20)
9191
.padding(.bottom, 20)
9292
}
93-
.frame(maxWidth: 480)
93+
.frame(maxWidth: 500)
9494
}
9595
}
9696

CodeEdit/Features/Git/Client/GitClient+Pull.swift

Lines changed: 0 additions & 17 deletions
This file was deleted.

CodeEdit/Features/NavigatorArea/Models/NavigatorTab.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ enum NavigatorTab: AreaTab {
4040
case .project:
4141
return "Project"
4242
case .sourceControl:
43-
return "Version Control"
43+
return "Source Control"
4444
case .search:
4545
return "Search"
4646
case .uiExtension(_, let data):

CodeEdit/Features/NavigatorArea/SourceControlNavigator/Changes/Views/SourceControlNavigatorChangesView.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ struct SourceControlNavigatorChangesView: View {
3232
if hasChanges || !hasRemotes || (!hasChanges && (hasUnsyncedCommits || hasCurrentBranch)) {
3333
VStack(spacing: 8) {
3434
Divided {
35+
if hasRemotes && (hasUnsyncedCommits || hasCurrentBranch) {
36+
SourceControlNavigatorSyncView(sourceControlManager: sourceControlManager)
37+
}
3538
if hasChanges {
3639
SourceControlNavigatorChangesCommitView()
3740
}
3841
if !hasRemotes {
3942
SourceControlNavigatorNoRemotesView()
4043
}
41-
if !hasChanges && (hasUnsyncedCommits || hasCurrentBranch) {
42-
SourceControlNavigatorSyncView(sourceControlManager: sourceControlManager)
43-
}
4444
}
4545
}
4646
.padding(.horizontal, 10)

CodeEdit/Features/NavigatorArea/SourceControlNavigator/Changes/Views/SourceControlNavigatorNoRemotesView.swift

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import SwiftUI
1010
struct SourceControlNavigatorNoRemotesView: View {
1111
@EnvironmentObject var sourceControlManager: SourceControlManager
1212

13-
@State private var addRemoteIsPresented: Bool = false
14-
1513
var body: some View {
1614
VStack(spacing: 0) {
1715
HStack {
@@ -25,10 +23,7 @@ struct SourceControlNavigatorNoRemotesView: View {
2523
)
2624
Spacer()
2725
Button("Add") {
28-
addRemoteIsPresented = true
29-
}
30-
.sheet(isPresented: $addRemoteIsPresented) {
31-
SourceControlAddRemoteView()
26+
sourceControlManager.addExistingRemoteSheetIsPresented = true
3227
}
3328
}
3429
}

CodeEdit/Features/NavigatorArea/SourceControlNavigator/Changes/Views/SourceControlNavigatorSyncView.swift

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,41 +12,46 @@ struct SourceControlNavigatorSyncView: View {
1212
@State private var isLoading: Bool = false
1313

1414
var body: some View {
15-
HStack {
16-
Label(title: {
17-
Text(
18-
formatUnsyncedlabel(
19-
ahead: sourceControlManager.numberOfUnsyncedCommits.ahead,
20-
behind: sourceControlManager.numberOfUnsyncedCommits.behind
21-
)
22-
)
23-
}, icon: {
24-
Image(systemName: "arrow.up.arrow.down")
25-
.foregroundStyle(.secondary)
26-
})
27-
Spacer()
28-
if sourceControlManager.numberOfUnsyncedCommits.behind > 0 {
29-
Button {
30-
self.pull()
31-
} label: {
32-
if isLoading {
33-
Text("Pulling...")
34-
} else {
35-
Text("Pull")
36-
}
15+
if let currentBranch = sourceControlManager.currentBranch {
16+
HStack {
17+
if currentBranch.upstream == nil {
18+
Label(title: {
19+
Text("No tracked branch for '\(sourceControlManager.currentBranch?.name ?? "")'")
20+
}, icon: {
21+
Image(symbol: "branch")
22+
.foregroundStyle(.secondary)
23+
})
24+
} else {
25+
Label(title: {
26+
Text(
27+
formatUnsyncedlabel(
28+
ahead: sourceControlManager.numberOfUnsyncedCommits.ahead,
29+
behind: sourceControlManager.numberOfUnsyncedCommits.behind
30+
)
31+
)
32+
}, icon: {
33+
Image(systemName: "arrow.up.arrow.down")
34+
.foregroundStyle(.secondary)
35+
})
3736
}
38-
.disabled(isLoading)
39-
} else if sourceControlManager.numberOfUnsyncedCommits.ahead > 0 {
40-
Button {
41-
self.push()
42-
} label: {
43-
if isLoading {
44-
Text("Pushing...")
45-
} else {
46-
Text("Push")
37+
38+
Spacer()
39+
if sourceControlManager.numberOfUnsyncedCommits.behind > 0 {
40+
Button {
41+
sourceControlManager.pullSheetIsPresented = true
42+
} label: {
43+
Text("Pull...")
44+
}
45+
.disabled(isLoading)
46+
} else if sourceControlManager.numberOfUnsyncedCommits.ahead > 0
47+
|| currentBranch.upstream == nil {
48+
Button {
49+
sourceControlManager.pushSheetIsPresented = true
50+
} label: {
51+
Text("Push...")
4752
}
53+
.disabled(isLoading)
4854
}
49-
.disabled(isLoading)
5055
}
5156
}
5257
}

CodeEdit/Features/NavigatorArea/SourceControlNavigator/History/Views/CommitListItemView.swift

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,19 +88,20 @@ struct CommitListItemView: View {
8888
if !commit.refs.isEmpty {
8989
HStack {
9090
ForEach(commit.refs, id: \.self) { ref in
91-
HStack {
91+
HStack(spacing: 2.5) {
9292
Image.branch
9393
.imageScale(.small)
94-
.foregroundColor(.primary)
94+
.foregroundColor(.secondary)
9595
.help(ref)
9696
Text(ref)
97-
.font(.system(size: 10, design: .monospaced))
9897
}
98+
.font(.system(size: 10))
9999
.frame(height: 13)
100100
.background(
101101
RoundedRectangle(cornerRadius: 3)
102102
.padding(.vertical, -1)
103-
.padding(.horizontal, -2.5)
103+
.padding(.leading, -2.5)
104+
.padding(.trailing, -4)
104105
.foregroundColor(Color(nsColor: .quaternaryLabelColor))
105106
)
106107
.padding(.trailing, 2.5)
@@ -109,20 +110,21 @@ struct CommitListItemView: View {
109110
}
110111

111112
if !commit.tag.isEmpty {
112-
HStack {
113-
Image.breakpoint
113+
HStack(spacing: 2.5) {
114+
Image(systemName: "tag")
114115
.imageScale(.small)
115116
.foregroundColor(.primary)
116117
.help(commit.tag)
117118
Text(commit.tag)
118-
.font(.system(size: 10, design: .monospaced))
119119
}
120+
.font(.system(size: 10))
120121
.frame(height: 13)
121122
.background(
122123
RoundedRectangle(cornerRadius: 3)
123124
.padding(.vertical, -1)
124-
.padding(.horizontal, -2.5)
125-
.foregroundColor(Color(nsColor: .selectedContentBackgroundColor))
125+
.padding(.leading, -2.5)
126+
.padding(.trailing, -4)
127+
.foregroundColor(Color(nsColor: .purple).opacity(0.2))
126128
)
127129
.padding(.trailing, 2.5)
128130
}

0 commit comments

Comments
 (0)