remote.go 867 B

12345678910111213141516171819202122232425262728293031
  1. // Copyright 2019 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package git
  5. import "strings"
  6. // RemoveRemote removes a remote from given repository path if exists.
  7. func RemoveRemote(repoPath, remote string) error {
  8. _, err := NewCommand("remote", "rm", remote).RunInDir(repoPath)
  9. if err != nil && !strings.Contains(err.Error(), "fatal: No such remote") {
  10. return err
  11. }
  12. return nil
  13. }
  14. // AddRemoteOptions contains options to add a remote address.
  15. type AddRemoteOptions struct {
  16. Mirror bool
  17. }
  18. // AddRemote adds a new remote
  19. func AddRemote(repoPath, remote, addr string, opts AddRemoteOptions) error {
  20. cmd := NewCommand("remote", "add", remote)
  21. if opts.Mirror {
  22. cmd.AddArguments("--mirror")
  23. }
  24. _, err := cmd.AddArguments(addr).RunInDir(repoPath)
  25. return err
  26. }