Skip to content

git.Worktree.Checkout with Force = true: behavior change in v5.7.0 (ignored files deleted) #796

@toddgiguere

Description

@toddgiguere

Our team has noticed a behavior change when upgrading from go-git v5.6.1 to v5.7.0 regarding the usage of Checkout() and the Force: true option.

In v5.6.1 and previous versions, if the current branch had any ignored files (.gitignore) and we used the Force: true option when checking out another branch, the ignored files were left in place.

In v5.7.0, using Force: true option, files that are untracked AND ignored are all deleted from the filesystem after branch switch with Checkout().

We have fixed the issue by using the option Keep: true instead of using the Force option, and now our ignored files are left alone on filesystem after switch of branches.

We did not know if we were incorrectly using Force to accomplish this before and a bug had been fixed in v5.7.0, or if this is not intended and a new bug has been introduced? If someone could confirm?

Example:
(Assume the current worktree directory has an ignored file that exists, and we are on a branch different than "test-branch")

resultErr := w.Checkout(&git.CheckoutOptions{
    Branch: plumbing.NewBranchReferenceName("test-branch"),
    Force:   true})

in v5.6.1 and previous, the ignored file will be left alone, in v5.7.0 it will be deleted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingno-autocloseIssues/PRs to be ignored by stale bot

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions