aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLiz Prucka <lizprucka@google.com>2023-06-05 10:23:32 -0500
committerAleksandr Nogikh <wp32pw@gmail.com>2023-06-15 21:16:10 +0200
commitf3921d4d63f97d1f1fb49a69ea85744bb7ef184b (patch)
treec7996c603dd5d855fb90c62235625805819b8d33
parentb27a175519cd5a94f2b1e259f9ceae8a585faf2c (diff)
pkg/vcs: force git branch checkout
We are currently seeing errors that there are "untracked working tree files which would be overrwritten by checkout". This error occurs when files of the same path differ between branches, regardless of whether the repository is clean or not. Forcing FETCH_HEAD checkout, then moving repair() to after checkout to clean repository to the current checkout. Additionally, added a second "force" to git clean to clean directories with '.git' subdirectories.
-rw-r--r--pkg/vcs/git.go12
1 files changed, 9 insertions, 3 deletions
diff --git a/pkg/vcs/git.go b/pkg/vcs/git.go
index 4ed33972c..3d5b3ca2f 100644
--- a/pkg/vcs/git.go
+++ b/pkg/vcs/git.go
@@ -114,12 +114,18 @@ func (git *git) CheckoutBranch(repo, branch string) (*Commit, error) {
if err != nil {
return nil, err
}
- if _, err := git.git("checkout", "FETCH_HEAD"); err != nil {
+ if _, err := git.git("checkout", "FETCH_HEAD", "--force"); err != nil {
return nil, err
}
if _, err := git.git("submodule", "update", "--init"); err != nil {
return nil, err
}
+ // If the branch checkout had to be "forced" the directory may
+ // contain remaining untracked files.
+ // Clean again to ensure the new branch is in a clean state.
+ if err := git.repair(); err != nil {
+ return nil, err
+ }
return git.HeadCommit()
}
@@ -177,8 +183,8 @@ func (git *git) reset() error {
return nil
}
git.git("reset", "--hard", "--recurse-submodules")
- git.git("clean", "-fdx")
- git.git("submodule", "foreach", "--recursive", "git", "clean", "-fdx")
+ git.git("clean", "-xfdf")
+ git.git("submodule", "foreach", "--recursive", "git", "clean", "-xfdf")
git.git("bisect", "reset")
_, err := git.git("reset", "--hard", "--recurse-submodules")
return err