Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent a "stash pop" if "stash" reports "No local changes to save" #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/commands/smart-merge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions lib/commands/smart-pull.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/git-smart/git_repo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down