Documentation ¶
Overview ¶
Package vcs manipulates and inspects VCS (Git and Mercurial) repositories.
Example ¶
package main import ( "fmt" "github.com/sourcegraph/go-vcs" "io/ioutil" "os" "path/filepath" ) func main() { var tmpdir string tmpdir, err := ioutil.TempDir("", "go-vcs-TestGit") if err != nil { panic("TempDir: " + err.Error()) return } defer os.RemoveAll(tmpdir) r, err := vcs.Git.Clone("https://bitbucket.org/sqs/go-vcs-gittest.git", tmpdir) if err != nil { fmt.Printf("Clone error: %s\n", err) return } // check out master masterDir, err := r.CheckOut("master") if err != nil { fmt.Printf("CheckOut master: %s\n", err) return } fmt.Printf("master foo: %s", readfile(filepath.Join(masterDir, "foo"))) // check out a branch barbranchDir, err := r.CheckOut("barbranch") if err != nil { fmt.Printf("CheckOut barbranch: %s\n", err) return } fmt.Printf("barbranch bar: %s", readfile(filepath.Join(barbranchDir, "bar"))) // check out a commit id barcommit := "f411e1ea59ed2b833291efa196e8dab80dbf7cb8" barcommitDir, err := r.CheckOut(barcommit) if err != nil { fmt.Printf("CheckOut barcommit %s: %s", barcommit, err) return } fmt.Printf("barcommit bar: %s", readfile(filepath.Join(barcommitDir, "bar"))) } func readfile(path string) string { data, _ := ioutil.ReadFile(path) return string(data) }
Output: master foo: Hello, foo barbranch bar: Hello, bar barcommit bar: Hello, bar
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var VCSByName = map[string]VCS{ "git": Git, "hg": Hg, }
Map of VCS name to VCS object.
Functions ¶
This section is empty.
Types ¶
type Repository ¶
type Repository interface { Dir() string // The repository's root directory. VCS() VCS // CurrentCommitID returns the commit ID of the HEAD or tip. CurrentCommitID() (string, error) // Downloads updates to the repository from the default remote. Download() error // CommitLog returns a list of commits in the current HEAD/tip. CommitLog() ([]*Commit, error) // CheckOut returns the path of a directory containing a working tree at revision rev. CheckOut // assumes that rev is local or has already been fetched; it does not update the repository. CheckOut(rev string) (dir string, err error) ReadFileAtRevision(path string, rev string) ([]byte, error) }
func Clone ¶
func Clone(vcs VCS, url, dir string) (Repository, error)
Clones the VCS repository from a remote URL to dir.
func CloneOrOpen ¶
func CloneOrOpen(vcs VCS, url, dir string) (Repository, error)
If no repository exists at dir, CloneOrOpen clones the VCS repository to dir. Otherwise, it opens the repository at dir (without checking that the repository there is, indeed, cloned from the specified URL).
type VCS ¶
type VCS interface { // Clones the repository at the given URL into dir. If dir already exists, the error os.ErrExist // is returned. Clone(url, dir string) (Repository, error) // CloneMirror clones a new mirror repository from url at dir. This // corresponds to `git clone --mirror`. CloneMirror(url, dir string) error // UpdateMirror updates a mirror repository from url at dir. This // corresponds to `git remote update`. UpdateMirror(dir string) error Open(dir string) (Repository, error) ShortName() string }
var Git VCS = git{"git"}
var Hg VCS = hg{"hg"}
Click to show internal directories.
Click to hide internal directories.