Skip to content

fix(push): we need to allow pushing to a remote by name and refspec #14

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

Merged
merged 1 commit into from
Jul 9, 2025

Conversation

aymanbagabas
Copy link
Member

This adds support for pushing to a remote by its name and branch name.

This adds support for pushing to a remote by its name and branch name.
@Copilot Copilot AI review requested due to automatic review settings July 7, 2025 22:16
@aymanbagabas aymanbagabas requested a review from pjbgf as a code owner July 7, 2025 22:16
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances the push command to allow specifying a remote by name (instead of URL) and pushing specific local branches by name without requiring full refspec syntax.

  • Added logic to load repository config and detect a remote by its configured name
  • Updated refspec handling: branch names are converted into forced +local:refs/heads/remote refspecs
  • Imported new packages (fmt, plumbing) to support the above changes
Comments suppressed due to low confidence (2)

cmd/gogit/push.go:71

  • This unconditionally generates a forced (+) refspec to refs/heads/..., overriding any user-supplied refspec syntax and force-pushing by default. Consider retaining original config.RefSpec(arg) if arg already appears to be a valid refspec pattern, or make forced vs. regular push optional.
				str := fmt.Sprintf("+%s:refs/heads/%s", ref.String(), ref.Short())

cmd/gogit/push.go:71

  • [nitpick] The variable name str is too generic. Consider renaming it to refspec or spec for clarity.
				str := fmt.Sprintf("+%s:refs/heads/%s", ref.String(), ref.Short())

Comment on lines +50 to +52
for remote := range cfg.Remotes {
if args[0] == remote {
remoteName = remote
Copy link
Preview

Copilot AI Jul 7, 2025

Choose a reason for hiding this comment

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

Iterating for remote := range cfg.Remotes yields integer indices, not remote names, so comparing args[0] == remote will not compile. Use for _, remote := range cfg.Remotes and compare args[0] == remote.Name.

Suggested change
for remote := range cfg.Remotes {
if args[0] == remote {
remoteName = remote
for _, remote := range cfg.Remotes {
if args[0] == remote.Name {
remoteName = remote.Name

Copilot uses AI. Check for mistakes.

@pjbgf pjbgf merged commit bc2a51a into go-git:main Jul 9, 2025
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