Permalink
Browse files

use merge instead of force branch update if branch already checked out

  • Loading branch information...
1 parent e73bed6 commit f67a646b031b1d53f8edb146237302beb50fcb68 @timcharper committed Mar 12, 2010
@@ -23,6 +23,7 @@ if File.exist?(".git/queue-rebase-run")
exit 0
end
+# Not pretty... but well tested!! Refactor me.
module GitMethods
def chdir_parent
Dir.chdir('..') until File.directory?('.git') || Dir.pwd == '/'
@@ -114,7 +115,11 @@ previous_submodules = list_submodules('HEAD@{1}')
divergent_commits=%x{git rev-list #{ref}..#{local_ref}}.strip
if divergent_commits.empty?
STDERR.puts "fastforwarding #{local_ref} to #{ref}"
- system("git branch -f #{local_ref} #{ref}")
+ if File.read(".git/HEAD").include?("ref: refs/heads/#{local_ref}")
+ system("git merge #{ref}")
+ else
+ system("git branch -f #{local_ref} #{ref}")
+ end
exec("git checkout #{local_ref}")
end
end
@@ -80,3 +80,24 @@ Feature: auto submodules
git rebase master
"""
Then the file "submod/.git/HEAD" should include "ref: refs/heads/submodule_next"
+
+ Scenario: fastforwarding when the branch is already checked out
+ When I run:
+ """
+ git checkout -b super_project_next
+ cd submod
+ echo submodule_next > README
+ git commit -m 'set README to next' -a
+ git push
+ cd ..
+ git commit -m "bump submodule" -a
+ cd submod
+ git reset --hard HEAD^
+ cd ..
+
+ git checkout master
+ """
+ Then the file "submod/README" should not include "submodule_next"
+ When I run "git checkout super_project_next"
+ Then the file "submod/README" should include "submodule_next"
+ Then the file "submod/.git/HEAD" should include "ref: refs/heads/master"
@@ -62,6 +62,12 @@
end
end
+Then /^the file "([^\"]*)" should not include "([^\"]*)"$/ do |filename, content|
+ in_current_dir do
+ File.read(filename).should_not include(content)
+ end
+end
+
Then /^the following (files|folders) should exist:$/ do |file_or_dir, table|
in_current_dir do
table.raw.map { |r| r.first}.each do |path|

0 comments on commit f67a646

Please sign in to comment.