-
Notifications
You must be signed in to change notification settings - Fork 811
Support pushing to an anonymous remote #1512
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
Open
mhagger
wants to merge
5
commits into
go-git:main
Choose a base branch
from
mhagger:push-to-anonymous-remote
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7664b62
config: introduce a constant, `AnonymousRemoteName`
mhagger 7fbb19b
git: add new `IsAnonymous()` methods
mhagger de378fc
config: add function `NewAnonymousRemoteConfig()`
mhagger 659e204
git: allow pushing to an anonymous remote
mhagger e9bb4b8
git: incorporate most of the PR feedback
mhagger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -357,33 +357,22 @@ func (s *RepositorySuite) TestCreateRemoteInvalid() { | |||||||
s.Nil(remote) | ||||||||
} | ||||||||
|
||||||||
func (s *RepositorySuite) TestCreateRemoteAnonymous() { | ||||||||
func (s *RepositorySuite) TestCreateRemoteEphemeral() { | ||||||||
r, _ := Init(memory.NewStorage(), nil) | ||||||||
remote, err := r.CreateRemoteAnonymous(&config.RemoteConfig{ | ||||||||
Name: "anonymous", | ||||||||
remote := NewRemote(r.Storer, &config.RemoteConfig{ | ||||||||
URLs: []string{"http://foo/foo.git"}, | ||||||||
}) | ||||||||
|
||||||||
s.NoError(err) | ||||||||
s.Equal("anonymous", remote.Config().Name) | ||||||||
s.Equal("", remote.Config().Name) | ||||||||
} | ||||||||
|
||||||||
func (s *RepositorySuite) TestCreateRemoteAnonymousInvalidName() { | ||||||||
func (s *RepositorySuite) TestCreateRemoteEphemeralInvalidName() { | ||||||||
r, _ := Init(memory.NewStorage(), nil) | ||||||||
remote, err := r.CreateRemoteAnonymous(&config.RemoteConfig{ | ||||||||
remote := NewRemote(r.Storer, &config.RemoteConfig{ | ||||||||
Name: "not_anonymous", | ||||||||
URLs: []string{"http://foo/foo.git"}, | ||||||||
}) | ||||||||
|
||||||||
s.ErrorIs(err, ErrAnonymousRemoteName) | ||||||||
s.Nil(remote) | ||||||||
} | ||||||||
|
||||||||
func (s *RepositorySuite) TestCreateRemoteAnonymousInvalid() { | ||||||||
r, _ := Init(memory.NewStorage(), nil) | ||||||||
remote, err := r.CreateRemoteAnonymous(&config.RemoteConfig{}) | ||||||||
|
||||||||
s.ErrorIs(err, config.ErrRemoteConfigEmptyName) | ||||||||
s.Nil(remote) | ||||||||
} | ||||||||
|
||||||||
|
@@ -1716,6 +1705,47 @@ func (s *RepositorySuite) TestPush() { | |||||||
}) | ||||||||
} | ||||||||
|
||||||||
func (s *RepositorySuite) TestPushEphemeral() { | ||||||||
url := s.T().TempDir() | ||||||||
|
||||||||
server, err := PlainInit(url, true) | ||||||||
s.NoError(err) | ||||||||
|
||||||||
// Make sure that there is an "origin" remote. It will _not_ be | ||||||||
// used, but we want to make sure that its remote-tracking | ||||||||
// branches are not incorrectly updated by the push. | ||||||||
c, err := s.Repository.Config() | ||||||||
s.NoError(err) | ||||||||
if _, ok := c.Remotes["origin"]; !ok { | ||||||||
// Create an "origin" remote. | ||||||||
_, err = s.Repository.CreateRemote(&config.RemoteConfig{ | ||||||||
Name: "origin", | ||||||||
URLs: []string{filepath.Join(url, "origin-not-used")}, | ||||||||
}) | ||||||||
s.NoError(err) | ||||||||
} | ||||||||
|
||||||||
err = s.Repository.Push(&PushOptions{ | ||||||||
RemoteURL: url, | ||||||||
}) | ||||||||
s.NoError(err) | ||||||||
|
||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's confirm no new remote was added.
Suggested change
|
||||||||
s.Len(c.Remotes, 1) | ||||||||
|
||||||||
AssertReferences(s.T(), server, map[string]string{ | ||||||||
"refs/heads/master": "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", | ||||||||
"refs/heads/branch": "e8d3ffab552895c19b9fcf7aa264d277cde33881", | ||||||||
}) | ||||||||
|
||||||||
// Make sure that remote-tracking references were _not_ created. | ||||||||
refs, err := s.Repository.References() | ||||||||
s.NoError(err) | ||||||||
refs.ForEach(func(r *plumbing.Reference) error { | ||||||||
s.False(strings.HasPrefix(r.Name().String(), "refs/remotes/")) | ||||||||
return nil | ||||||||
}) | ||||||||
} | ||||||||
|
||||||||
func (s *RepositorySuite) TestPushContext() { | ||||||||
url, err := os.MkdirTemp("", "") | ||||||||
s.NoError(err) | ||||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Validate logic will have to be slightly amended for this to work.