forked from src-d/go-git
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add Repository.CreateRemoteAnonymous
Signed-off-by: niukuo <[email protected]>
- Loading branch information
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -49,6 +49,7 @@ var ( | |
ErrRepositoryAlreadyExists = errors.New("repository already exists") | ||
ErrRemoteNotFound = errors.New("remote not found") | ||
ErrRemoteExists = errors.New("remote already exists") | ||
ErrAnonymousRemoteName = errors.New("anonymous remote name must be 'anonymous'") | ||
ErrWorktreeNotProvided = errors.New("worktree should be provided") | ||
ErrIsBareRepository = errors.New("worktree not available in a bare repository") | ||
ErrUnableToResolveCommit = errors.New("unable to resolve commit") | ||
|
@@ -492,6 +493,22 @@ func (r *Repository) CreateRemote(c *config.RemoteConfig) (*Remote, error) { | |
return remote, r.Storer.SetConfig(cfg) | ||
} | ||
|
||
// CreateRemoteAnonymous creates a new anonymous remote. c.Name must be "anonymous". | ||
// It's used like 'git fetch [email protected]:src-d/go-git.git master:master'. | ||
func (r *Repository) CreateRemoteAnonymous(c *config.RemoteConfig) (*Remote, error) { | ||
if err := c.Validate(); err != nil { | ||
return nil, err | ||
} | ||
|
||
if c.Name != "anonymous" { | ||
return nil, ErrAnonymousRemoteName | ||
} | ||
|
||
remote := newRemote(r.Storer, c) | ||
|
||
return remote, nil | ||
} | ||
|
||
// DeleteRemote delete a remote from the repository and delete the config | ||
func (r *Repository) DeleteRemote(name string) error { | ||
cfg, err := r.Storer.Config() | ||
|
This file contains 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