Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit f071b7f

Browse files
committed
Keep local changes when checkout branch in worktree.
1 parent e17ee11 commit f071b7f

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

options.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,11 @@ type CheckoutOptions struct {
242242
// Force, if true when switching branches, proceed even if the index or the
243243
// working tree differs from HEAD. This is used to throw away local changes
244244
Force bool
245+
// Keep, if true when switching branches, local changes (the index or the
246+
// working tree changes) will be kept so that they can be committed to the
247+
// target branch. Force and Keep are mutually exclusive, should not be both
248+
// set to true.
249+
Keep bool
245250
}
246251

247252
// Validate validates the fields and sets the default values.

worktree.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ func (w *Worktree) Checkout(opts *CheckoutOptions) error {
160160
ro := &ResetOptions{Commit: c, Mode: MergeReset}
161161
if opts.Force {
162162
ro.Mode = HardReset
163+
} else if opts.Keep {
164+
ro.Mode = SoftReset
163165
}
164166

165167
if !opts.Hash.IsZero() && !opts.Create {

0 commit comments

Comments
 (0)