diff --git a/lib/commands/smart-merge.rb b/lib/commands/smart-merge.rb index 0912a46..b0453e3 100644 --- a/lib/commands/smart-merge.rb +++ b/lib/commands/smart-merge.rb @@ -42,17 +42,17 @@ end #Before we merge, detect if there are local changes and stash them. - stash_required = repo.dirty? - if stash_required + pop_required = false + if repo.dirty? note "Working directory dirty. Stashing..." - repo.stash! + pop_required = repo.stash! end #Perform the merge, using --no-ff. repo.merge_no_ff!(merge_target) - #If we stashed before, pop now. - if stash_required + #If we successfully stashed before, pop now. + if pop_required note "Reapplying local changes..." repo.stash_pop! end diff --git a/lib/commands/smart-pull.rb b/lib/commands/smart-pull.rb index cf0423d..02dd9cb 100644 --- a/lib/commands/smart-pull.rb +++ b/lib/commands/smart-pull.rb @@ -70,10 +70,10 @@ note "There #{is_are} #{new_commits_on_remote.length} new commit#{s_or_not} on '#{upstream_branch}'." #Next, detect if there are local changes and stash them. - stash_required = repo.dirty? - if stash_required + pop_required = false + if repo.dirty? note "Working directory dirty. Stashing..." - repo.stash! + pop_required = repo.stash! end success_messages = [] @@ -95,8 +95,8 @@ success_messages << "HEAD moved from #{head[0,7]} to #{repo.sha('HEAD')[0,7]}." end - #If we stashed before, pop now. - if stash_required + #If we successfully stashed before, pop now. + if pop_required note "Reapplying local changes..." repo.stash_pop! end diff --git a/lib/git-smart/git_repo.rb b/lib/git-smart/git_repo.rb index f7f5993..607de12 100644 --- a/lib/git-smart/git_repo.rb +++ b/lib/git-smart/git_repo.rb @@ -82,7 +82,7 @@ def fast_forward!(upstream) end def stash! - git!('stash') + !git!('stash').split("\n").include?("No local changes to save") end def stash_pop!