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

Draft: Migrate Git Implementation to SwiftGitX #1990

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

ibrahimcetin
Copy link
Contributor

Description

This pull request represents an incremental migration of the current Git implementation to SwiftGitX. While the code is still a work in progress and may have some rough edges, I aim to provide a foundational understanding of how SwiftGitX can be integrated. I'll continue to refine and clean up the code in subsequent updates.

Related Issues

Checklist

  • I read and understood the contributing guide as well as the code of conduct
  • The issues this PR addresses are related to each other
  • My changes generate no new warnings
  • My code builds and runs on my machine
  • My changes are all related to the related issue above
  • I documented my code

Copy link
Contributor

@hi2gage hi2gage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some food for thought comments.

Comment on lines +43 to +48
// .gitClient
// .getCommitHistory(
// maxCount: 40,
// fileLocalPath: fileURL,
// showMergeCommits: Settings.shared.preferences.sourceControl.git.showMergeCommitsPerFileLog
// )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be commented out or deleted?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't delete it because I didn't understand what showMergeCommits does and prefers to keep it for now to don't forget.

@@ -188,7 +188,10 @@ extension SourceControlManager {

/// Commit files selected by user
func commit(message: String, details: String? = nil) async throws {
try await gitClient.commit(message: message, details: details)
guard let repository else { return }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find guarding on repository in these places confusing. I understand that we need to be able to unwrap this optional object. But I don't think the call sites of this function should ever be shown unless a valid repository exists.

This feels like a great use of a lock and key pattern. Here is a good conference talk that goes over it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, I just put it there for now because I am not sure the optimal solution for optional repository property.

@@ -197,13 +200,15 @@ extension SourceControlManager {
/// Adds the given URLs to the staged changes.
/// - Parameter files: The files to stage.
func add(_ files: [URL]) async throws {
try await gitClient.add(files)
guard let repository else { return }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

}

/// Removes the given URLs from the staged changes.
/// - Parameter files: The URLs to un-stage.
func reset(_ files: [URL]) async throws {
try await gitClient.reset(files)
guard let repository else { return }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

gitClient = GitClient(directoryURL: workspaceURL, shellClient: currentWorld.shellClient)
repository = try? Repository.open(at: workspaceURL)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be catching these these errors anywhere or should we always assume that if this fails it's because the repository does not exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could handle this by using a throws initializer to catch other possible errors, but doing so would introduce more code changes. For now, I’ll add a TODO to revisit this.


struct CommitListItemView: View {

var commit: GitCommit
var commit: Commit
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of changes here which is fine because of the difference in structure between the two structs. But I'm curious if the other models are also different in SwiftGitX?

Makes me wonder if makes sense to actually just map SwiftGitX to the models that current exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will use SwiftGitX structures as much as possible since they are more structured and better suited for a maintainable implementation. I think we should eventually remove the GitClient implementation from the project.

While mapping SwiftGitX to the existing models is an option, it might introduce unnecessary complexity. SwiftGitX already provides well-defined structures, and adapting them directly could be a cleaner approach in the long run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants