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

cmd(git): More commands #465

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

cmd(git): More commands #465

wants to merge 2 commits into from

Conversation

tony
Copy link
Member

@tony tony commented Jun 18, 2024

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.

Copy link

codecov bot commented Jun 18, 2024

Codecov Report

Attention: Patch coverage is 66.90141% with 47 lines in your changes missing coverage. Please review.

Project coverage is 54.44%. Comparing base (dbe22d2) to head (1534338).

Files with missing lines Patch % Lines
src/libvcs/cmd/git.py 63.28% 42 Missing and 5 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #465      +/-   ##
==========================================
+ Coverage   54.08%   54.44%   +0.36%     
==========================================
  Files          40       40              
  Lines        3635     3745     +110     
  Branches      793      808      +15     
==========================================
+ Hits         1966     2039      +73     
- Misses       1318     1350      +32     
- Partials      351      356       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tony tony force-pushed the more-git-cmds branch 3 times, most recently from ff046f3 to 5dff81e Compare June 24, 2024 00:02
@tony tony force-pushed the more-git-cmds branch 8 times, most recently from 8808231 to 700a4fa Compare July 4, 2024 23:01
@tony tony force-pushed the more-git-cmds branch 3 times, most recently from f520132 to af58b49 Compare July 20, 2024 11:39
@tony tony force-pushed the more-git-cmds branch 2 times, most recently from adfbeaa to 76822c5 Compare August 3, 2024 12:20
@tony tony force-pushed the more-git-cmds branch 4 times, most recently from 8adff4c to c843022 Compare August 10, 2024 19:57
@tony tony force-pushed the more-git-cmds branch 3 times, most recently from 8839c2a to 0385215 Compare August 16, 2024 23:56
@tony tony force-pushed the more-git-cmds branch 2 times, most recently from 11dbd6a to 8578585 Compare August 26, 2024 10:50
@tony tony force-pushed the more-git-cmds branch 4 times, most recently from 2e5347d to bb6d40e Compare September 6, 2024 23:56
tony added a commit that referenced this pull request Oct 12, 2024
@tony tony force-pushed the more-git-cmds branch 3 times, most recently from a7c9389 to 3eb99a5 Compare October 13, 2024 20:40
@tony tony force-pushed the more-git-cmds branch 3 times, most recently from 9298d30 to 6547a77 Compare October 27, 2024 09:24
@tony tony force-pushed the master branch 2 times, most recently from 7f69eab to c480bb4 Compare November 24, 2024 15:12
@tony tony force-pushed the more-git-cmds branch 2 times, most recently from 2d78366 to 8ad81a7 Compare December 14, 2024 00:09
@tony tony force-pushed the more-git-cmds branch 7 times, most recently from 6a0495c to 1617b69 Compare December 24, 2024 22:25
@tony
Copy link
Member Author

tony commented Jan 11, 2025

@sourcery-ai review

Copy link

sourcery-ai bot commented Jan 11, 2025

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
Loading

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"
Loading

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

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @tony - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@@ -390,7 +395,7 @@ def clone(
def fetch(
Copy link

Choose a reason for hiding this comment

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

issue (code-quality): Low code quality found in Git.fetch - 6% (low-code-quality)


ExplanationThe quality score for this function is below the quality threshold of 25%.
This score is a combination of the method length, cognitive complexity and working memory.

How can you solve this?

It might be worth refactoring this function to make it shorter and more readable.

  • Reduce the function length by extracting pieces of functionality out into
    their own functions. This is the most important thing you can do - ideally a
    function should be less than 10 lines.
  • Reduce nesting, perhaps by introducing guard clauses to return early.
  • Ensure that variables are tightly scoped, so that code using related concepts
    sits together within the function rather than being scattered.

@@ -746,7 +751,7 @@
def pull(
Copy link

Choose a reason for hiding this comment

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

issue (code-quality): Low code quality found in Git.pull - 1% (low-code-quality)


ExplanationThe quality score for this function is below the quality threshold of 25%.
This score is a combination of the method length, cognitive complexity and working memory.

How can you solve this?

It might be worth refactoring this function to make it shorter and more readable.

  • Reduce the function length by extracting pieces of functionality out into
    their own functions. This is the most important thing you can do - ideally a
    function should be less than 10 lines.
  • Reduce nesting, perhaps by introducing guard clauses to return early.
  • Ensure that variables are tightly scoped, so that code using related concepts
    sits together within the function rather than being scattered.

Comment on lines +2792 to +2796
if isinstance(path, pathlib.Path):
self.path = path
else:
self.path = pathlib.Path(path)

Copy link

Choose a reason for hiding this comment

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

suggestion (code-quality): Replace if statement with if expression (assign-if-exp)

Suggested change
if isinstance(path, pathlib.Path):
self.path = path
else:
self.path = pathlib.Path(path)
self.path = path if isinstance(path, pathlib.Path) else pathlib.Path(path)


if mirror is not None:
if isinstance(mirror, str):
assert any(f for f in ["push", "fetch"])
Copy link

Choose a reason for hiding this comment

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

suggestion (code-quality): Simplify generator expression (simplify-generator)

Suggested change
assert any(f for f in ["push", "fetch"])
assert any(["push", "fetch"])

Comment on lines +3336 to +3340
if isinstance(path, pathlib.Path):
self.path = path
else:
self.path = pathlib.Path(path)

Copy link

Choose a reason for hiding this comment

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

suggestion (code-quality): Replace if statement with if expression (assign-if-exp)

Suggested change
if isinstance(path, pathlib.Path):
self.path = path
else:
self.path = pathlib.Path(path)
self.path = path if isinstance(path, pathlib.Path) else pathlib.Path(path)

Comment on lines +3459 to +3463
if isinstance(path, pathlib.Path):
self.path = path
else:
self.path = pathlib.Path(path)

Copy link

Choose a reason for hiding this comment

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

suggestion (code-quality): Replace if statement with if expression (assign-if-exp)

Suggested change
if isinstance(path, pathlib.Path):
self.path = path
else:
self.path = pathlib.Path(path)
self.path = path if isinstance(path, pathlib.Path) else pathlib.Path(path)

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.

1 participant