aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/git/git.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2018-04-24 13:12:40 +0200
committerDmitry Vyukov <dvyukov@google.com>2018-04-24 13:23:01 +0200
commit9366d03f001170479319878905031f63d4377c46 (patch)
tree6d9c06b2fffb9e29f81b8b746e218e2db914aa3b /pkg/git/git.go
parente2f4bf8f3818d49baf0f3789add75d5fd506ad8d (diff)
dashboard/app: allow testing fixes on exact commit and without patch
This implements 2 features: 1. It's now possible to specify exact commit when testing as: 2. It's possible to test without patch attached assuming the patch is already committed to the tested tree. Fixes #558
Diffstat (limited to 'pkg/git/git.go')
-rw-r--r--pkg/git/git.go34
1 files changed, 22 insertions, 12 deletions
diff --git a/pkg/git/git.go b/pkg/git/git.go
index 372309634..77a2630f2 100644
--- a/pkg/git/git.go
+++ b/pkg/git/git.go
@@ -57,9 +57,9 @@ func Poll(dir, repo, branch string) (*Commit, error) {
return HeadCommit(dir)
}
-// Checkout checkouts the specified repository/branch in dir.
+// CheckoutBranch checkouts the specified repository/branch in dir.
// It does not fetch history and efficiently supports checkouts of different repos in the same dir.
-func Checkout(dir, repo, branch string) (*Commit, error) {
+func CheckoutBranch(dir, repo, branch string) (*Commit, error) {
if _, err := runSandboxed(dir, "git", "reset", "--hard"); err != nil {
if err := initRepo(dir); err != nil {
return nil, err
@@ -75,21 +75,21 @@ func Checkout(dir, repo, branch string) (*Commit, error) {
return HeadCommit(dir)
}
-// CheckoutCommit checkouts the specified repository/branch/commit in dir.
-func CheckoutCommit(dir, repo, branch, commit string) error {
+// CheckoutCommit checkouts the specified repository on the specified commit in dir.
+func CheckoutCommit(dir, repo, commit string) (*Commit, error) {
if _, err := runSandboxed(dir, "git", "reset", "--hard"); err != nil {
if err := initRepo(dir); err != nil {
- return err
+ return nil, err
}
}
- _, err := runSandboxed(dir, "git", "fetch", repo, branch)
+ _, err := runSandboxed(dir, "git", "fetch", repo)
if err != nil {
- return err
+ return nil, err
}
if _, err := runSandboxed(dir, "git", "checkout", commit); err != nil {
- return err
+ return nil, err
}
- return nil
+ return HeadCommit(dir)
}
func clone(dir, repo, branch string) error {
@@ -322,11 +322,21 @@ func CheckRepoAddress(repo string) bool {
return gitRepoRe.MatchString(repo)
}
-var gitRepoRe = regexp.MustCompile(`^(git|ssh|http|https|ftp|ftps)://[a-zA-Z0-9-_]+(\.[a-zA-Z0-9-_]+)+(:[0-9]+)?/[a-zA-Z0-9-_./]+\.git(/)?$`)
-
// CheckBranch does a best-effort approximate check of a git branch name.
func CheckBranch(branch string) bool {
return gitBranchRe.MatchString(branch)
}
-var gitBranchRe = regexp.MustCompile("^[a-zA-Z0-9-_/.]{2,200}$")
+func CheckCommitHash(hash string) bool {
+ if !gitHashRe.MatchString(hash) {
+ return false
+ }
+ ln := len(hash)
+ return ln == 8 || ln == 10 || ln == 12 || ln == 16 || ln == 20 || ln == 40
+}
+
+var (
+ gitRepoRe = regexp.MustCompile(`^(git|ssh|http|https|ftp|ftps)://[a-zA-Z0-9-_]+(\.[a-zA-Z0-9-_]+)+(:[0-9]+)?/[a-zA-Z0-9-_./]+\.git(/)?$`)
+ gitBranchRe = regexp.MustCompile("^[a-zA-Z0-9-_/.]{2,200}$")
+ gitHashRe = regexp.MustCompile("^[a-f0-9]+$")
+)