Beispiel #1
0
Datei: bzr.go Projekt: dvln/vcs
// BzrExists verifies the local repo or remote location is of the Bzr repo type,
// returns where it was found ("" if not found) and any error.  If it does not
// exist a wrapped ErrNoExist error is returned (use out.IsError() to check)
func BzrExists(e Existence, l Location) (string, Resulter, error) {
	results := newResults()
	var err error
	path := ""
	if l == LocalPath {
		if exists, err := dir.Exists(e.LocalRepoPath() + "/.bzr"); exists && err == nil {
			return e.LocalRepoPath(), nil, nil
		}
		err = out.WrapErrf(ErrNoExist, 4505, "Local bzr location, \"%s\", does not exist, err: %s", e.LocalRepoPath(), err)
	} else { // checking remote "URL" as well as possible for current VCS..
		remote := e.Remote()
		scheme := url.GetScheme(remote)
		// if we have a scheme then just see if the repo exists...
		if scheme != "" {
			var result *Result
			result, err = run(bzrTool, "info", remote)
			results.add(result)
			if err == nil {
				path = remote
			}
		} else {
			vcsSchemes := e.Schemes()
			for _, scheme = range vcsSchemes {
				var result *Result
				result, err = run(bzrTool, "info", scheme+"://"+remote)
				results.add(result)
				if err == nil {
					path = scheme + "://" + remote
					break
				}
			}
		}
		if err == nil {
			return path, results, nil
		}
		err = out.WrapErrf(ErrNoExist, 4506, "Remote bzr location, \"%s\", does not exist, err: %s", e.Remote(), err)
	}
	return path, results, err
}
Beispiel #2
0
Datei: git.go Projekt: dvln/vcs
// GitExists verifies the local repo or remote location is a Git repo,
// returns where it was found (or "" if not found), the results
// of any git cmds run (cmds and related output) and any error.
// Note that if no git cmds run then Resulter won't have any data
// (which occurs if the git repo is local). If the git repo does not
// exist a wrapped ErrNoExist is returned (use out.IsError() to check)
func GitExists(e Existence, l Location) (string, Resulter, error) {
	results := newResults()
	var err error
	path := ""
	if l == LocalPath {
		_, _, err = findGitDirs(e.LocalRepoPath()) // clone? wrapped ErrNoExists if not
		if err == nil {
			return e.LocalRepoPath(), nil, nil // it's a local git clone, success
		}
	} else { // checking remote "URL" as well as possible for current VCS..
		remote := e.Remote()
		scheme := url.GetScheme(remote)
		if scheme != "" { // if we have a scheme then see if the repo exists...
			var result *Result
			result, err = run(gitTool, "ls-remote", remote)
			results.add(result)
			if err == nil {
				path = remote
			}
		} else {
			vcsSchemes := e.Schemes()
			for _, scheme = range vcsSchemes {
				var result *Result
				result, err = run(gitTool, "ls-remote", scheme+"://"+remote)
				results.add(result)
				if err == nil {
					path = scheme + "://" + remote
					break
				}
			}
		}
		if err == nil {
			return path, results, nil
		}
		err = out.WrapErrf(ErrNoExist, 4501, "Remote git location does not exist: %s\n  run err: %s", e.Remote(), err)
	}
	return path, results, err
}