Exemple #1
0
Fichier : git.go Projet : dvln/vcs
// isBareRepo is a simple routine to see if a repo has a .git/ dir (non-bare),
// otherwise it it assumed to be a bare repo, Param:
//	path (string): path to repo (should already have existence check done)
// Returns true if (likely) bare, false otherwise
func isBareRepo(path string) bool {
	bare := true
	if exists, err := dir.Exists(filepath.Join(path, ".git")); exists && err == nil {
		bare = false // see if it's bare or not
	}
	return bare
}
Exemple #2
0
Fichier : git.go Projet : dvln/vcs
// findGitDirs expects to be pointed at a git workspace, either
// bare or standard.  It'll find the gitdir and worktree dirs
// and return them, if it fails it'll return non-nil err.  Params:
//	path (string): path to the git workspace
// Returns:
//	gitDir (string): path to git metadata location
//	workTreeDir (string): working tree, "" if bare clone
//	err (error): a valid error if unable to find a git repo
func findGitDirs(path string) (string, string, error) {
	gitDir := filepath.Join(path, ".git") // see if std git clone
	var err error
	var exists bool
	if exists, err = dir.Exists(gitDir); exists && err == nil {
		return gitDir, path, nil
	}
	gitRefsDir := filepath.Join(path, "refs")
	if exists, err = dir.Exists(gitRefsDir); exists && err == nil {
		gitConfigFile := filepath.Join(path, "config")
		if exists, err = file.Exists(gitConfigFile); exists && err == nil {
			return path, "", nil
		}
	}

	if err == nil {
		return "", "", out.WrapErrf(ErrNoExist, 4500, "Unable to find valid git clone under path: %s", path)
	}
	return "", "", out.WrapErrf(ErrNoExist, 4500, "Unable to find valid git clone under path: %s\n  existence err: %s", path, err)
}
Exemple #3
0
Fichier : bzr.go Projet : 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
}
Exemple #4
0
func TestWkspcRootDetermination(t *testing.T) {
	tempFolder, err := ioutil.TempDir("", "dvln-wkspc-test")
	if err != nil {
		t.Fatal(err)
	}
	defer os.RemoveAll(tempFolder)

	fakeWkspcSubDir := filepath.Join(tempFolder, "fake_wkspc_subdir")

	if err := dir.CreateIfNotExists(fakeWkspcSubDir); err != nil {
		t.Fatal(err)
	}
	fileinfo, err := os.Stat(fakeWkspcSubDir)
	if err != nil {
		t.Fatalf("Should have create a folder, got %v", err)
	}
	if !fileinfo.IsDir() {
		t.Fatalf("Should have been a dir, seems it's not")
	}
	exists, err := dir.Exists(fakeWkspcSubDir)
	if err != nil {
		t.Fatal("Folder should have existed but instead an error was returned")
	}
	if !exists {
		t.Fatal("Folder should have existed but Exists() said it did not")
	}

	wsRootFolder := filepath.Join(tempFolder, ".dvln")
	if err := dir.CreateIfNotExists(wsRootFolder); err != nil {
		t.Fatal(err)
	}
	fileinfo, err = os.Stat(wsRootFolder)
	if err != nil {
		t.Fatalf("Should have create a .dvln folder, got %v", err)
	}
	if !fileinfo.IsDir() {
		t.Fatalf("Should have been a dir, seems .dvln is not")
	}
	exists, err = dir.Exists(wsRootFolder)
	if err != nil {
		t.Fatal("Folder .dvln should have existed but instead an error was returned")
	}
	if !exists {
		t.Fatal("Folder .dvln should have existed but Exists() said it did not")
	}

	root, err := RootDir(fakeWkspcSubDir)
	if err != nil {
		t.Fatalf("Search for workspace root from %s should not have returned an error, got %v", fakeWkspcSubDir, err)
	}
	if root == "" {
		t.Fatal("Failed to find the workspace root folder, it should have been found")
	}
	if root != tempFolder {
		t.Fatalf("Found a workspace root but didn't match expected (found: %s, expected: %s)", root, tempFolder)
	}

	privTempFolder := filepath.Join("/", "private", tempFolder)
	root, err = RootDir(tempFolder)
	if err != nil {
		t.Fatalf("Search for a workspace root dir (from the workspace root dir) got unexpected error: %v", err)
	}
	if root == "" {
		t.Fatal("Failed to find the workspace root directory (from that dir), it should have been found")
	}
	if root != tempFolder && root != privTempFolder {
		t.Fatalf("Root found to be %s, should have been set to %s", root, tempFolder)
	}

	os.Chdir(fakeWkspcSubDir)
	root, err = RootDir()
	if err != nil {
		t.Fatalf("Search for workspace root after Chdir into wkspc subdir should not have returned an error, got %v", err)
	}
	if root == "" {
		t.Fatal("After chdir, failed to find the workspace root folder, it should have been found")
	}
	if root != tempFolder && root != privTempFolder {
		t.Fatalf("After chdir, found a workspace root but didn't match expected (found: %s, expected: %s)", root, tempFolder)
	}
}