From f071b7f44750afaf17438c036d9c8345bdce457b Mon Sep 17 00:00:00 2001 From: Linuxer Wang Date: Fri, 3 May 2019 09:46:54 -0700 Subject: [PATCH] Keep local changes when checkout branch in worktree. --- options.go | 5 +++++ worktree.go | 2 ++ 2 files changed, 7 insertions(+) diff --git a/options.go b/options.go index 7c9e68728..a3b14fe2d 100644 --- a/options.go +++ b/options.go @@ -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. diff --git a/worktree.go b/worktree.go index dae40a38a..1b104492b 100644 --- a/worktree.go +++ b/worktree.go @@ -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 {