libvcs icon indicating copy to clipboard operation
libvcs copied to clipboard

cmd(git): More commands

Open tony opened this issue 1 year ago • 3 comments

Changes

Commands (git)

Add GitBranch (git.branch) - instance-based mutations of a branch

  • Create git checkout -b <branchname>
  • Checkout git checkout <branchname>
  • Remove
  • Rename
  • Move

Summary by Sourcery

Add the GitBranchManager to manage Git branches. Update GitRemoteCmd to GitRemoteManager.

New Features:

  • Add a GitBranch class to provide instance-based mutations of a branch, including creating, checking out, removing, renaming, and moving branches.

Tests:

  • Update tests to reflect the changes in the GitRemoteCmd and GitBranch classes.

tony avatar Jun 18 '24 20:06 tony

Codecov Report

Attention: Patch coverage is 78.88199% with 68 lines in your changes missing coverage. Please review.

Project coverage is 56.57%. Comparing base (43b41ab) to head (908b72a).

Files with missing lines Patch % Lines
src/libvcs/cmd/git.py 65.21% 55 Missing and 9 partials :warning:
tests/cmd/test_git.py 96.77% 4 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #465      +/-   ##
==========================================
+ Coverage   54.09%   56.57%   +2.47%     
==========================================
  Files          40       40              
  Lines        3627     3894     +267     
  Branches      793      822      +29     
==========================================
+ Hits         1962     2203     +241     
- Misses       1314     1333      +19     
- Partials      351      358       +7     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Jun 18 '24 20:06 codecov[bot]

@sourcery-ai review

tony avatar Jan 11 '25 20:01 tony

Reviewer's Guide by Sourcery

This pull request introduces a new way to manage Git branches using a new instance-based approach. It adds a GitBranchManager class and a GitBranchCmd class, which provide methods for creating, checking out, removing, renaming, and moving branches. It also refactors the GitRemoteCmd class to GitRemoteManager and GitRemoteCmd to provide a similar instance-based approach for managing remotes.

Sequence diagram for branch creation and checkout

sequenceDiagram
    participant Client
    participant Git
    participant GitBranchManager
    participant GitBranchCmd

    Client->>Git: branches.create(branch='feature')
    Git->>GitBranchManager: create(branch='feature')
    GitBranchManager->>GitBranchCmd: new GitBranchCmd(branch_name='feature')
    GitBranchCmd-->>GitBranchManager: branch command object
    GitBranchManager->>GitBranchCmd: create()
    GitBranchCmd-->>GitBranchManager: result
    GitBranchManager-->>Git: result
    Git-->>Client: result

Class diagram for Git branch and remote management changes

classDiagram
    class Git {
        +remotes: GitRemoteManager
        +branches: GitBranchManager
        +stash: GitStashCmd
    }

    class GitRemoteManager {
        +path: Path
        +run()
        +add()
        +show()
        +ls(): QueryList[GitRemoteCmd]
        +get(): GitRemoteCmd
        +filter(): list[GitRemoteCmd]
    }

    class GitRemoteCmd {
        +remote_name: str
        +fetch_url: str
        +push_url: str
        +rename()
        +remove()
        +show()
        +prune()
        +get_url()
        +set_url()
    }

    class GitBranchManager {
        +path: Path
        +run()
        +checkout()
        +create()
        +ls(): QueryList[GitBranchCmd]
        +get(): GitBranchCmd
        +filter(): list[GitBranchCmd]
    }

    class GitBranchCmd {
        +branch_name: str
        +checkout()
        +create()
    }

    Git *-- GitRemoteManager
    Git *-- GitBranchManager
    GitRemoteManager ..> GitRemoteCmd : creates
    GitBranchManager ..> GitBranchCmd : creates

    note for GitRemoteManager "New instance-based approach"
    note for GitBranchManager "New instance-based approach"

File-Level Changes

Change Details Files
Added GitBranchManager and GitBranchCmd classes for managing Git branches.
  • Introduced the GitBranchManager class to manage Git branches.
  • Introduced the GitBranchCmd class to perform operations on individual branches.
  • Added a branches attribute to the Git class to access the GitBranchManager.
  • Added methods to GitBranchManager for creating, checking out, removing, renaming, and moving branches.
  • Added methods to GitBranchCmd for performing operations on individual branches, such as checking out and creating branches.
src/libvcs/cmd/git.py
Refactored GitRemoteCmd to GitRemoteManager and GitRemoteCmd.
  • Introduced the GitRemoteManager class to manage Git remotes.
  • Introduced the GitRemoteCmd class to perform operations on individual remotes.
  • Changed the remotes attribute of the Git class to access the GitRemoteManager.
  • Updated the GitSync class to use the new GitRemoteManager.
  • Updated tests to reflect the changes in the GitRemoteCmd and GitSync classes.
src/libvcs/cmd/git.py
src/libvcs/sync/git.py
tests/sync/test_git.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in the pull request body to generate a PR summary at any time. You can also use this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

  • Contact our support team for questions or feedback.
  • Visit our documentation for detailed guides and information.
  • Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.

sourcery-ai[bot] avatar Jan 11 '25 20:01 sourcery-ai[bot]