// GitAddRemote adds a new git remote
424220
func (s *Action) GitAddRemote(ctx context.Context, c *cli.Context) error {
	store := c.String("store")
	remote := c.Args().Get(0)
	url := c.Args().Get(1)

	if remote == "" || url == "" {
		return ExitError(ctx, ExitUsage, nil, "Usage: %s git remote add <REMOTE> <URL>", s.Name)
	}

	return s.Store.GitAddRemote(ctx, store, remote, url)
}
92339
func (r *Remote) Push(o *PushOptions) error {
	return r.PushContext(context.Background(), o)
}
347263
func (g *Git) AddRemote(ctx context.Context, remote, url string) error {
	_, err := g.repo.CreateRemote(&config.RemoteConfig{
		Name: remote,
		URLs: []string{url},
	})
	return err
}
304263
func GitHookService() macaron.Handler {
	return func(c *Context) {
		if !c.User.CanEditGitHook() {
			c.NotFound()
			return
		}
	}
}
248659
func (g *Gitlab) ProjectDeployKey(id, keyId string) (*SshKey, *ResponseMeta, error) {
	u := g.ResourceUrl(ProjectDeployKeyApiPath, map[string]string{
		":id":     id,
		":key_id": keyId,
	})

	var deployKey *SshKey

	contents, meta, err := g.buildAndExecRequest("GET", u.String(), nil)
	if err == nil {
		err = json.Unmarshal(contents, &deployKey)
	}

	return deployKey, meta, err
}
935350
func (s *GitScanner) RemoteForPush(r string) error {
	s.mu.Lock()
	defer s.mu.Unlock()

	if len(s.remote) > 0 && s.remote != r {
		return fmt.Errorf("Trying to set remote to %q, already set to %q", r, s.remote)
	}

	s.remote = r
	s.skippedRefs = calcSkippedRefs(r)
	return nil
}
1219322
func hapiRemoteTokensDelete(w http.ResponseWriter, r *http.Request) {
	if os.Getenv("ABOT_ENV") != "test" {
		if !isAdmin(w, r) {
			return
		}
		if !isLoggedIn(w, r) {
			return
		}
		if !isValidCSRF(w, r) {
			return
		}
	}
	var req struct {
		Token string
		Email string
	}
	if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
		writeErrorBadRequest(w, err)
		return
	}
	q := `DELETE FROM remotetokens WHERE token=$1`
	res, err := db.Exec(q, req.Token)
	if err != nil {
		writeErrorInternal(w, err)
		return
	}
	rows, err := res.RowsAffected()
	if err != nil {
		writeErrorInternal(w, err)
		return
	}
	if rows == 0 {
		writeErrorBadRequest(w, errors.New("invalid token or email"))
		return
	}
	w.WriteHeader(http.StatusOK)
}
886288
func WithRemoteAddrUser(uid, gid int) DaemonOpt {
	return func(r *remote) error {
		r.GRPC.UID = uid
		r.GRPC.GID = gid
		return nil
	}
}
469126
func GitilesCommitURL(c *pb.GitilesCommit) string {
	return fmt.Sprintf("%s/+/%s", GitilesRepoURL(c), c.Id)
}
321222
func (rc *refCommits) pop() (commit *gitpb.Commit, empty bool) {
	commit, rc.commits = rc.commits[0], rc.commits[1:]
	return commit, len(rc.commits) == 0
}
525412
func RemoteAddrHandler(name string) func(next xhandler.HandlerC) xhandler.HandlerC {
	return func(next xhandler.HandlerC) xhandler.HandlerC {
		return xhandler.HandlerFuncC(func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
			if host, _, err := net.SplitHostPort(r.RemoteAddr); err == nil {
				FromContext(ctx).SetField(name, host)
			}
			next.ServeHTTPC(ctx, w, r)
		})
	}
}
931376
func (k *KeybaseDaemonLocal) PutGitMetadata(
	ctx context.Context, folder keybase1.Folder, repoID keybase1.RepoID,
	metadata keybase1.GitLocalMetadata) error {
	return nil
}
326676
func (g *Git) Cmd(context.Context, string, ...string) error {
	return fmt.Errorf("not supported")
}
74114
func (gs *gitSource) mountRemote(ctx context.Context, remote string) (target string, release func(), retErr error) {
	remoteKey := "git-remote::" + remote

	sis, err := gs.md.Search(remoteKey)
	if err != nil {
		return "", nil, errors.Wrapf(err, "failed to search metadata for %s", remote)
	}

	var remoteRef cache.MutableRef
	for _, si := range sis {
		remoteRef, err = gs.cache.GetMutable(ctx, si.ID())
		if err != nil {
			if cache.IsLocked(err) {
				// should never really happen as no other function should access this metadata, but lets be graceful
				logrus.Warnf("mutable ref for %s  %s was locked: %v", remote, si.ID(), err)
				continue
			}
			return "", nil, errors.Wrapf(err, "failed to get mutable ref for %s", remote)
		}
		break
	}

	initializeRepo := false
	if remoteRef == nil {
		remoteRef, err = gs.cache.New(ctx, nil, cache.CachePolicyRetain, cache.WithDescription(fmt.Sprintf("shared git repo for %s", remote)))
		if err != nil {
			return "", nil, errors.Wrapf(err, "failed to create new mutable for %s", remote)
		}
		initializeRepo = true
	}

	releaseRemoteRef := func() {
		remoteRef.Release(context.TODO())
	}

	defer func() {
		if retErr != nil && remoteRef != nil {
			releaseRemoteRef()
		}
	}()

	mount, err := remoteRef.Mount(ctx, false)
	if err != nil {
		return "", nil, err
	}

	lm := snapshot.LocalMounter(mount)
	dir, err := lm.Mount()
	if err != nil {
		return "", nil, err
	}

	defer func() {
		if retErr != nil {
			lm.Unmount()
		}
	}()

	if initializeRepo {
		if _, err := gitWithinDir(ctx, dir, "", "init", "--bare"); err != nil {
			return "", nil, errors.Wrapf(err, "failed to init repo at %s", dir)
		}

		if _, err := gitWithinDir(ctx, dir, "", "remote", "add", "origin", remote); err != nil {
			return "", nil, errors.Wrapf(err, "failed add origin repo at %s", dir)
		}

		// same new remote metadata
		si, _ := gs.md.Get(remoteRef.ID())
		v, err := metadata.NewValue(remoteKey)
		v.Index = remoteKey
		if err != nil {
			return "", nil, err
		}

		if err := si.Update(func(b *bolt.Bucket) error {
			return si.SetValue(b, "git-remote", v)
		}); err != nil {
			return "", nil, err
		}
	}
	return dir, func() {
		lm.Unmount()
		releaseRemoteRef()
	}, nil
}
1079915
func gitRemotes(path string) (map[string]string, error) {
	var stderr, stdout bytes.Buffer

	cmd := exec.Command("git", "remote", "-v")
	cmd.Dir = path
	cmd.Stdout = &stdout
	cmd.Stderr = &stderr
	if err := cmd.Run(); err != nil {
		return nil, fmt.Errorf("error getting git remotes: %s\nstdout: %s\nstderr: %s",
			err, stdout.String(), stderr.String())
	}

	// Read each line of output as a remote
	result := make(map[string]string)
	scanner := bufio.NewScanner(&stdout)
	for scanner.Scan() {
		line := scanner.Text()
		split := strings.Split(line, "\t")

		if len(split) < 2 {
			return nil, fmt.Errorf("invalid response from git remote: %s", stdout.String())
		}

		remote := fmt.Sprintf("remote.%s", strings.TrimSpace(split[0]))
		if _, ok := result[remote]; !ok {
			// https://github.com/foo/bar.git (fetch) #=> https://github.com/foo/bar.git
			urlSplit := strings.Split(split[1], " ")
			result[remote] = strings.TrimSpace(urlSplit[0])
		}
	}

	return result, nil
}
1181523
func (n *Node) doRaftAddPeer(conn redcon.Conn, cmd redcon.Command) (interface{}, error) {
	if len(cmd.Args) != 2 {
		return nil, ErrWrongNumberOfArguments
	}
	n.log.Noticef("Received add peer request from %v", string(cmd.Args[1]))
	f := n.raft.AddPeer(string(cmd.Args[1]))
	if f.Error() != nil {
		return nil, f.Error()
	}
	n.log.Noticef("Node %v added successfully", string(cmd.Args[1]))
	conn.WriteString("OK")
	return nil, nil
}
190464
func (r *RemoteService) AddRemoteBindingListener(bindingListener cluster.RemoteBindingListener) {
	r.remoteBindingListeners = append(r.remoteBindingListeners, bindingListener)
}