Пример #1
0
func (r *Repository) CrossRepoMergeBase(a vcs.CommitID, repoB vcs.Repository, b vcs.CommitID) (vcs.CommitID, error) {
	// libgit2 Repository inherits GitRootDir and CrossRepo from its
	// embedded gitcmd.Repository.

	var repoBDir string // path to head repo on local filesystem
	if repoB, ok := repoB.(gitcmd.CrossRepo); ok {
		repoBDir = repoB.GitRootDir()
	} else {
		return "", fmt.Errorf("git cross-repo merge-base not supported against repo type %T", repoB)
	}

	if repoBDir == r.Dir {
		return r.MergeBase(a, b)
	}

	r.editLock.Lock()
	defer r.editLock.Unlock()

	rem, err := r.createAndFetchFromAnonRemote(repoBDir)
	if err != nil {
		return "", err
	}
	defer rem.Free()

	return r.mergeBaseHoldingEditLock(a, b)
}
Пример #2
0
func (r *Repository) CrossRepoDiff(base vcs.CommitID, headRepo vcs.Repository, head vcs.CommitID, opt *vcs.DiffOptions) (diff *vcs.Diff, err error) {
	// libgit2 Repository inherits GitRootDir and CrossRepo from its
	// embedded gitcmd.Repository.

	var headDir string // path to head repo on local filesystem
	if headRepo, ok := headRepo.(gitcmd.CrossRepo); ok {
		headDir = headRepo.GitRootDir()
	} else {
		return nil, fmt.Errorf("git cross-repo diff not supported against head repo type %T", headRepo)
	}

	if headDir == r.Dir {
		return r.Diff(base, head, opt)
	}

	r.editLock.Lock()
	defer r.editLock.Unlock()

	rem, err := r.createAndFetchFromAnonRemote(headDir)
	if err != nil {
		return nil, err
	}
	defer rem.Free()

	return r.diffHoldingEditLock(base, head, opt)
}
Пример #3
0
func (r *Repository) CrossRepoDiff(base vcs.CommitID, headRepo vcs.Repository, head vcs.CommitID, opt *vcs.DiffOptions) (*vcs.Diff, error) {
	var headDir string // path to head repo on local filesystem
	if headRepo, ok := headRepo.(CrossRepo); ok {
		headDir = headRepo.GitRootDir()
	} else {
		return nil, fmt.Errorf("git cross-repo diff not supported against head repo type %T", headRepo)
	}

	if headDir == r.Dir {
		return r.Diff(base, head, opt)
	}

	if err := r.fetchRemote(headDir); err != nil {
		return nil, err
	}

	return r.Diff(base, head, opt)
}
Пример #4
0
func (r *Repository) CrossRepoMergeBase(a vcs.CommitID, repoB vcs.Repository, b vcs.CommitID) (vcs.CommitID, error) {
	// git.Repository inherits GitRootDir and CrossRepo from its
	// embedded gitcmd.Repository.

	var repoBDir string // path to head repo on local filesystem
	if repoB, ok := repoB.(CrossRepo); ok {
		repoBDir = repoB.GitRootDir()
	} else {
		return "", fmt.Errorf("git cross-repo merge-base not supported against repo type %T", repoB)
	}

	if repoBDir != r.Dir {
		if err := r.fetchRemote(repoBDir); err != nil {
			return "", err
		}
	}

	return r.MergeBase(a, b)
}
Пример #5
0
func cloneCmd(args []string) {
	fs := flag.NewFlagSet("clone", flag.ExitOnError)
	urlStr := fs.String("url", "http://localhost:"+defaultPort, "base URL to a running vcsstore API server")
	sshKeyFile := fs.String("i", "", "ssh private key file for clone remote")
	fs.Usage = func() {
		fmt.Fprintln(os.Stderr, `usage: vcsstore clone [options] repo-id vcs-type clone-url

Clones a repository on the server. Once finished, the repository will be
available to the client via the vcsstore API.

The options are:
`)
		fs.PrintDefaults()
		os.Exit(1)
	}
	fs.Parse(args)

	if fs.NArg() != 3 {
		fs.Usage()
	}

	baseURL, err := url.Parse(*urlStr)
	if err != nil {
		log.Fatal(err)
	}

	repoPath, vcsType := fs.Arg(0), fs.Arg(1)
	cloneURL, err := url.Parse(fs.Arg(2))
	if err != nil {
		log.Fatal(err)
	}

	var repo vcs.Repository
	c := vcsclient.New(baseURL, nil)
	repo, err = c.Repository(repoPath)
	if err != nil {
		log.Fatal("Open repository: ", err)
	}

	var opt vcs.RemoteOpts
	if *sshKeyFile != "" {
		key, err := ioutil.ReadFile(*sshKeyFile)
		if err != nil {
			log.Fatal(err)
		}
		opt.SSH = &vcs.SSHConfig{PrivateKey: key}
	}

	if repo, ok := repo.(vcsclient.RepositoryCloneUpdater); ok {
		err := repo.CloneOrUpdate(&vcsclient.CloneInfo{
			VCS: vcsType, CloneURL: cloneURL.String(), RemoteOpts: opt,
		})
		if err != nil {
			log.Fatal("Clone: ", err)
		}
	} else {
		log.Fatalf("Remote cloning is not implemented for %T.", repo)
	}

	fmt.Printf("%-5s cloned OK\n", repoPath)
}