Use git --single-branch and --depth whenever possible - closes #13
diff --git a/alldocs.go b/alldocs.go
index fe7563c..1461e7d 100644
--- a/alldocs.go
+++ b/alldocs.go
@@ -21,7 +21,7 @@
Fetch a remote dependency
Usage:
- gvt fetch [-branch branch | -revision rev | -tag tag] [-precaire] [-no-recurse] importpath
+ gvt fetch [-branch branch] [-revision rev | -tag tag] [-precaire] [-no-recurse] importpath
fetch vendors an upstream import path.
@@ -30,23 +30,22 @@
Flags:
-branch branch
- fetch from the name branch. If not supplied the default upstream
- branch will be used.
+ fetch from the named branch. Will also be used by gvt update.
+ If not supplied the default upstream branch will be used.
-no-recurse
do not fetch recursively.
-tag tag
- fetch the specified tag. If not supplied the default upstream
- branch will be used.
+ fetch the specified tag.
-revision rev
- fetch the specific revision from the branch (if supplied). If no
- revision supplied, the latest available will be supplied.
+ fetch the specific revision from the branch or repository.
+ If no revision supplied, the latest available will be fetched.
-precaire
allow the use of insecure protocols.
Restore dependencies from manifest
Usage:
- gvt restore
+ gvt restore [-precaire] [-connections N]
restore fetches the dependencies listed in the manifest.
diff --git a/fetch.go b/fetch.go
index ef16489..34aedbb 100644
--- a/fetch.go
+++ b/fetch.go
@@ -34,7 +34,7 @@
var cmdFetch = &Command{
Name: "fetch",
- UsageLine: "fetch [-branch branch | -revision rev | -tag tag] [-precaire] [-no-recurse] importpath",
+ UsageLine: "fetch [-branch branch] [-revision rev | -tag tag] [-precaire] [-no-recurse] importpath",
Short: "fetch a remote dependency",
Long: `fetch vendors an upstream import path.
@@ -43,16 +43,15 @@
Flags:
-branch branch
- fetch from the name branch. If not supplied the default upstream
- branch will be used.
+ fetch from the named branch. Will also be used by gvt update.
+ If not supplied the default upstream branch will be used.
-no-recurse
do not fetch recursively.
-tag tag
- fetch the specified tag. If not supplied the default upstream
- branch will be used.
+ fetch the specified tag.
-revision rev
- fetch the specific revision from the branch (if supplied). If no
- revision supplied, the latest available will be supplied.
+ fetch the specific revision from the branch or repository.
+ If no revision supplied, the latest available will be fetched.
-precaire
allow the use of insecure protocols.
diff --git a/gbvendor/repo.go b/gbvendor/repo.go
index 5a52c2b..54b9b40 100644
--- a/gbvendor/repo.go
+++ b/gbvendor/repo.go
@@ -274,16 +274,18 @@
return g.url
}
-// Checkout fetchs the remote branch, tag, or revision. If more than one is
-// supplied, an error is returned. If the branch is blank,
-// then the default remote branch will be used. If the branch is "HEAD", an
-// error will be returned.
+// Checkout fetchs the remote branch, tag, or revision. If the branch is blank,
+// then the default remote branch will be used. If the branch is "HEAD" and
+// revision is empty, an impossible update is assumed.
func (g *gitrepo) Checkout(branch, tag, revision string) (WorkingCopy, error) {
- if branch == "HEAD" {
+ if branch == "HEAD" && revision == "" {
return nil, fmt.Errorf("cannot update %q as it has been previously fetched with -tag or -revision. Please use gvt delete then fetch again.", g.url)
}
- if !atMostOne(branch, tag, revision) {
- return nil, fmt.Errorf("only one of branch, tag or revision may be supplied")
+ if !atMostOne(tag, revision) {
+ return nil, fmt.Errorf("only one of tag or revision may be supplied")
+ }
+ if !atMostOne(branch, tag) {
+ return nil, fmt.Errorf("only one of branch or tag may be supplied")
}
dir, err := mktmp()
if err != nil {
@@ -293,23 +295,37 @@
path: dir,
}
+ quiet := false
args := []string{
"clone",
"-q", // silence progress report to stderr
g.url,
dir,
}
- if branch != "" {
- args = append(args, "--branch", branch)
+ if branch != "" && branch != "HEAD" {
+ args = append(args, "--branch", branch, "--single-branch")
+ }
+ if tag != "" {
+ quiet = true // git REALLY wants to tell you how awesome 'detached HEAD' is...
+ args = append(args, "--branch", tag, "--single-branch")
+ args = append(args, "--depth", "1")
+ }
+ if revision == "" {
+ args = append(args, "--depth", "1")
}
- if _, err := run("git", args...); err != nil {
+ if quiet {
+ err = runQuiet("git", args...)
+ } else {
+ _, err = run("git", args...)
+ }
+ if err != nil {
wc.Destroy()
return nil, err
}
- if revision != "" || tag != "" {
- if err := runOutPath(os.Stderr, dir, "git", "checkout", "-q", oneOf(revision, tag)); err != nil {
+ if revision != "" {
+ if err := runOutPath(os.Stderr, dir, "git", "checkout", "-q", revision); err != nil {
wc.Destroy()
return nil, err
}
@@ -509,6 +525,14 @@
return cmd.Run()
}
+func runQuiet(c string, args ...string) error {
+ cmd := exec.Command(c, args...)
+ cmd.Stdin = nil
+ cmd.Stdout = nil
+ cmd.Stderr = nil
+ return cmd.Run()
+}
+
func runPath(path string, c string, args ...string) ([]byte, error) {
var buf bytes.Buffer
err := runOutPath(&buf, path, c, args...)
diff --git a/restore.go b/restore.go
index eedeaf5..a19959d 100644
--- a/restore.go
+++ b/restore.go
@@ -96,6 +96,8 @@
if err != nil {
return fmt.Errorf("dependency could not be processed: %s", err)
}
+ // We can't pass the branch here, and benefit from narrow clones, as the
+ // revision might not be in the branch tree anymore. Thanks rebase.
wc, err := repo.Checkout("", "", dep.Revision)
if err != nil {
return fmt.Errorf("dependency could not be fetched: %s", err)