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

Commit

Permalink
Keep local changes when checkout branch in worktree.
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxerwang committed May 3, 2019
1 parent e17ee11 commit f071b7f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,11 @@ type CheckoutOptions struct {
// Force, if true when switching branches, proceed even if the index or the
// working tree differs from HEAD. This is used to throw away local changes
Force bool
// Keep, if true when switching branches, local changes (the index or the
// working tree changes) will be kept so that they can be committed to the
// target branch. Force and Keep are mutually exclusive, should not be both
// set to true.
Keep bool
}

// Validate validates the fields and sets the default values.
Expand Down
2 changes: 2 additions & 0 deletions worktree.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ func (w *Worktree) Checkout(opts *CheckoutOptions) error {
ro := &ResetOptions{Commit: c, Mode: MergeReset}
if opts.Force {
ro.Mode = HardReset
} else if opts.Keep {
ro.Mode = SoftReset
}

if !opts.Hash.IsZero() && !opts.Create {
Expand Down

0 comments on commit f071b7f

Please sign in to comment.