From 1a489367849b97125c856b39a043570a237110e4 Mon Sep 17 00:00:00 2001 From: richo Date: Mon, 12 Nov 2012 11:22:42 +1100 Subject: [PATCH 1/4] Actually check out the branch after creating it. allow specification of a ref to set the new branch's head to --- lib/babushka/git_repo.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/babushka/git_repo.rb b/lib/babushka/git_repo.rb index c2839c603..a29339b8b 100644 --- a/lib/babushka/git_repo.rb +++ b/lib/babushka/git_repo.rb @@ -236,8 +236,8 @@ def clone! from end # Create a new local branch called +branch+, switching to it. - def branch! branch - repo_shell("git branch '#{branch}'") + def branch! branch, ref=nil + repo_shell("git checkout -b '#{branch}' '#{ref || "HEAD"}'") end # Create a new local tracking branch for +branch+, which should be specified From 4ad7863583ac3fa6533fee282ffcb3ae7dc0c689 Mon Sep 17 00:00:00 2001 From: richo Date: Mon, 12 Nov 2012 11:24:54 +1100 Subject: [PATCH 2/4] Update specs for GitRepo#branch! --- spec/babushka/git_repo_spec.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spec/babushka/git_repo_spec.rb b/spec/babushka/git_repo_spec.rb index 5904a6a82..3d9dc4df5 100644 --- a/spec/babushka/git_repo_spec.rb +++ b/spec/babushka/git_repo_spec.rb @@ -469,6 +469,9 @@ def repo_context name, &block it "should not be tracking anything" do subject.repo_shell('git config branch.next.remote').should be_nil end + it "should have checked out the next branch" do + subject.current_branch.should == "next" + end end end From 9020a1dd973d30f1aad4fbf39957dd2b37a5e778 Mon Sep 17 00:00:00 2001 From: Ben Hoskings Date: Sun, 25 Nov 2012 14:34:22 +1100 Subject: [PATCH 3/4] It was the code that was right, not the docs :) GitRepo#branch should only create the branch, and not check it out. --- lib/babushka/git_repo.rb | 5 +++-- spec/babushka/git_repo_spec.rb | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/babushka/git_repo.rb b/lib/babushka/git_repo.rb index a29339b8b..486703911 100644 --- a/lib/babushka/git_repo.rb +++ b/lib/babushka/git_repo.rb @@ -235,9 +235,10 @@ def clone! from } end - # Create a new local branch called +branch+, switching to it. + # Create a new local branch called +branch+ with +ref+ (defaulting to + # HEAD) as its tip. def branch! branch, ref=nil - repo_shell("git checkout -b '#{branch}' '#{ref || "HEAD"}'") + repo_shell("git branch '#{branch}' '#{ref || "HEAD"}'") end # Create a new local tracking branch for +branch+, which should be specified diff --git a/spec/babushka/git_repo_spec.rb b/spec/babushka/git_repo_spec.rb index 3d9dc4df5..302a16baf 100644 --- a/spec/babushka/git_repo_spec.rb +++ b/spec/babushka/git_repo_spec.rb @@ -462,15 +462,15 @@ def repo_context name, &block subject.branches.should_not include('next') end context "after branching" do - before { subject.branch! "next" } - it "should have created a next branch" do + before(:all) { subject.branch! "next" } + it "should have created the branch" do subject.branches.should include('next') end it "should not be tracking anything" do subject.repo_shell('git config branch.next.remote').should be_nil end - it "should have checked out the next branch" do - subject.current_branch.should == "next" + it "should not have checked out the branch" do + subject.current_branch.should == "master" end end end From ab27c1e5bdc5929057860f34f79fd176ce823447 Mon Sep 17 00:00:00 2001 From: Ben Hoskings Date: Sun, 25 Nov 2012 14:53:02 +1100 Subject: [PATCH 4/4] Spec that GitRepo#branch! starts branches at the supplied ref. --- spec/babushka/git_repo_spec.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/spec/babushka/git_repo_spec.rb b/spec/babushka/git_repo_spec.rb index 302a16baf..23f42598d 100644 --- a/spec/babushka/git_repo_spec.rb +++ b/spec/babushka/git_repo_spec.rb @@ -466,6 +466,9 @@ def repo_context name, &block it "should have created the branch" do subject.branches.should include('next') end + it "should have pointed the branch at HEAD" do + subject.resolve('next').should == subject.resolve("master") + end it "should not be tracking anything" do subject.repo_shell('git config branch.next.remote').should be_nil end @@ -473,6 +476,27 @@ def repo_context name, &block subject.current_branch.should == "master" end end + context "after branching to a ref" do + before(:all) { + cd(tmp_prefix / 'repos/a') { + shell 'echo "Ch-ch-ch-changes" >> content.txt' + shell 'git commit -a -m "Changes!"' + } + subject.branch! "another", "master~" + } + it "should have created the branch" do + subject.branches.should include('another') + end + it "should have pointed the branch at the right ref" do + subject.resolve('another').should == subject.resolve("master~") + end + it "should not be tracking anything" do + subject.repo_shell('git config branch.another.remote').should be_nil + end + it "should not have checked out the branch" do + subject.current_branch.should == "master" + end + end end describe GitRepo, '#track!' do