diff options
author | niukuo <niukuo@gmail.com> | 2019-03-22 16:32:01 +0800 |
---|---|---|
committer | niukuo <niukuo@gmail.com> | 2019-03-22 16:32:01 +0800 |
commit | 8b789adc353780b4a6688e8d2b3e8f47e60bf487 (patch) | |
tree | 8480ad07bae7f61d8c87a337cdc51d1b0167f880 /repository.go | |
parent | e704ed55d364c1e5ceefbf47c4280c1904d6b1ca (diff) | |
download | go-git-8b789adc353780b4a6688e8d2b3e8f47e60bf487.tar.gz |
add Repository.CreateRemoteAnonymous
Signed-off-by: niukuo <niukuo@gmail.com>
Diffstat (limited to 'repository.go')
-rw-r--r-- | repository.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/repository.go b/repository.go index de92d64..e5b12b0 100644 --- a/repository.go +++ b/repository.go @@ -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 git@github.com: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() |