提交 f3921d4d 编写于 作者: L Liz Prucka 提交者: Aleksandr Nogikh

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.
上级 b27a1755
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册