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

Added source control push and pull functionality #1785

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

austincondiff
Copy link
Collaborator

@austincondiff austincondiff commented Jul 1, 2024

Description

Added push and pull sheet.
Renamed Features/Git to Features/SourceControl and moved sheet views into it from the Source Control Navigator.

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
  6. You can now make changes, commit, and push via the Changes tab in the Source Control Navigator
  7. You can set up additional projects by repeating steps 1-5 so you can make changes elsewhere and test pull functionality.
  8. You can create additional remotes as well to test managing a project with multiple remotes, pushing and pulling from them, etc.

Checklist

  • Add push logic
  • Add pull logic
  • Add push sheet
  • Add pull sheet
  • Add centralized sheets view
  • Rename Features/Git to Features/SourceControl
  • Move sheet views into Features/SourceControl
  • Add "Source Control" menu
  • Add remote from push and pull sheets
  • Add fetch to the menu and display fetching sheet while fetching

  • 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

Screenshots

image image image image image image

…trol and moved sheet views into it from the Source Control Navigator.
@austincondiff austincondiff changed the title Added Source Control Push and Pull functionality Added source control push and pull functionality Jul 1, 2024
@austincondiff
Copy link
Collaborator Author

austincondiff commented Jul 2, 2024

I am struggling to get the "Source Control" menu working here, specifically trying to gain access to the focused windows SourceControlManager. The commands view can't find it so we are not showing those items as a result. Anyone know why? I tried placing .focusedObject(sourceControlManager) at the end of WorkspaceView but that wasn't working.

@austincondiff austincondiff marked this pull request as ready for review July 2, 2024 22:15
Copy link
Contributor

@FastestMolasses FastestMolasses left a comment

Choose a reason for hiding this comment

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

LGTM, just small changes

@matthijseikelenboom
Copy link
Contributor

Looks good, but no tests are present

@austincondiff
Copy link
Collaborator Author

@matthijseikelenboom We need a separate issue to add tests to not just what I did in this PR but everything source control related.

command += " \(remote) \(branch)"
}

if rebase == true {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are you checking if it's explicitly true?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Because it might be either nil or false.

Copy link
Contributor

@nanashili nanashili Jul 3, 2024

Choose a reason for hiding this comment

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

It never needs to be nil only false or true, i would opt for always returning false instead of nil


extension GitClient {
/// Pull changes from remote
func pullFromRemote(remote: String? = nil, branch: String? = nil, rebase: Bool? = nil) async throws {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are the params optional, these would almost always be required.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Users can do a git pull and it will pull their current branch without needing to specify. I am keeping close to how git works in this regard. Probably not extremely necessary.

Copy link
Contributor

Choose a reason for hiding this comment

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

Using just git pull is not very effective when it comes to big projects. I would perhaps rethink how this is managed. Because if something goes wrong with git users won't be too happy

func pullFromRemote(remote: String? = nil, branch: String? = nil, rebase: Bool? = nil) async throws {
var command = "pull"

if let remote = remote, let branch = branch {
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be done better in my opinion:

func pullFromRemote(remote: String = "origin",
                    branch: String = "main", 
                    rebase: Bool = false) async throws {
    var command = "pull"

    if remote == "" {
        print("Remote needs to be specified")
        return
    }

    if branch == "" {
        print("Branch needs to specified")
        return
    }

    command += " \(remote) \(branch)"

    if rebase {
        command += " --rebase"
    }

    _ = try await self.run(command)
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You are making the assumption that their default branch is "main".

Copy link
Contributor

Choose a reason for hiding this comment

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

You are making the assumption that their default branch is "main".

Nope, just an example, because you would always need to pull the origin and branch regardless

Copy link
Contributor

@matthijseikelenboom matthijseikelenboom Jul 3, 2024

Choose a reason for hiding this comment

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

I think you'd want to default to nothing, in case of remote name and branch name.

The rebase value should indeed be non-nullable. But, since there is also the option to use --merge or --ff-only. might want to make it an inner private enum, instead of a boolean.

But if you'd follow clean code, you want four functions:
pullFromRemoteWithRebase
pullFromRemoteWithMerge
pullFromRemoteWithFastForward
pullFromRemoteWithGlobalConfig
Or something like that. Having a (boolean) flag is bad practice

Copy link
Contributor

@nanashili nanashili Jul 4, 2024

Choose a reason for hiding this comment

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

I would suggest making that one function instead of multiple, you would end up with repetitive code if you make multiple functions

https://github.com/AuroraEditor/Version-Control-Kit/blob/main/Sources/Version-Control/Base/Commands/Pull.swift

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.

None yet

5 participants