aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2019-03-13 14:52:01 +0100
committerDmitry Vyukov <dvyukov@google.com>2019-03-17 18:06:44 +0100
commit1f6fc9f1880fe2dc4be0702329d0c537eecff860 (patch)
tree8d405f5d6596e8af97ba2f895b241f2d394a53ee
parent8bfa7f8698abc8fe3d88bdaf583824faf0a77eb5 (diff)
pkg/vcs: reset repo more
If we cherry-pick some fixes during bisection we need to "git reset" repo before "git bisect reset". Otherwise it will fail. Reset repo in more points. Update #501
-rw-r--r--pkg/vcs/git.go22
1 files changed, 15 insertions, 7 deletions
diff --git a/pkg/vcs/git.go b/pkg/vcs/git.go
index 210c5b154..785300038 100644
--- a/pkg/vcs/git.go
+++ b/pkg/vcs/git.go
@@ -35,8 +35,7 @@ func newGit(dir string, ignoreCC map[string]bool) *git {
func (git *git) Poll(repo, branch string) (*Commit, error) {
dir := git.dir
- runSandboxed(dir, "git", "bisect", "reset")
- runSandboxed(dir, "git", "reset", "--hard")
+ git.reset()
origin, err := runSandboxed(dir, "git", "remote", "get-url", "origin")
if err != nil || strings.TrimSpace(string(origin)) != repo {
// The repo is here, but it has wrong origin (e.g. repo in config has changed), re-clone.
@@ -67,7 +66,7 @@ func (git *git) Poll(repo, branch string) (*Commit, error) {
func (git *git) CheckoutBranch(repo, branch string) (*Commit, error) {
dir := git.dir
- runSandboxed(dir, "git", "bisect", "reset")
+ git.reset()
if _, err := runSandboxed(dir, "git", "reset", "--hard"); err != nil {
if err := git.initRepo(err); err != nil {
return nil, err
@@ -85,7 +84,7 @@ func (git *git) CheckoutBranch(repo, branch string) (*Commit, error) {
func (git *git) CheckoutCommit(repo, commit string) (*Commit, error) {
dir := git.dir
- runSandboxed(dir, "git", "bisect", "reset")
+ git.reset()
if _, err := runSandboxed(dir, "git", "reset", "--hard"); err != nil {
if err := git.initRepo(err); err != nil {
return nil, err
@@ -107,6 +106,7 @@ func (git *git) fetchRemote(repo string) error {
func (git *git) SwitchCommit(commit string) (*Commit, error) {
dir := git.dir
+ runSandboxed(dir, "git", "reset", "--hard")
if _, err := runSandboxed(dir, "git", "checkout", commit); err != nil {
return nil, err
}
@@ -126,6 +126,13 @@ func (git *git) clone(repo, branch string) error {
return nil
}
+func (git *git) reset() {
+ // This function tries to reset git repo state to a known clean state.
+ runSandboxed(git.dir, "git", "reset", "--hard")
+ runSandboxed(git.dir, "git", "bisect", "reset")
+ runSandboxed(git.dir, "git", "reset", "--hard")
+}
+
func (git *git) initRepo(reason error) error {
if reason != nil {
log.Logf(1, "git: initializing repo at %v: %v", git.dir, reason)
@@ -356,8 +363,7 @@ func splitEmail(email string) (user, domain string, err error) {
func (git *git) Bisect(bad, good string, trace io.Writer, pred func() (BisectResult, error)) ([]*Commit, error) {
dir := git.dir
- runSandboxed(dir, "git", "bisect", "reset")
- runSandboxed(dir, "git", "reset", "--hard")
+ git.reset()
firstBad, err := git.getCommit(bad)
if err != nil {
return nil, err
@@ -366,7 +372,7 @@ func (git *git) Bisect(bad, good string, trace io.Writer, pred func() (BisectRes
if err != nil {
return nil, err
}
- defer runSandboxed(dir, "git", "bisect", "reset")
+ defer git.reset()
fmt.Fprintf(trace, "# git bisect start %v %v\n%s", bad, good, output)
current, err := git.HeadCommit()
if err != nil {
@@ -379,6 +385,8 @@ func (git *git) Bisect(bad, good string, trace io.Writer, pred func() (BisectRes
}
for {
res, err := pred()
+ // Linux EnvForCommit may cherry-pick some fixes, reset these before the next step.
+ runSandboxed(dir, "git", "reset", "--hard")
if err != nil {
return nil, err
}