Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'git-branch' -- add a 'ref' param, and update specs & do…

…cs to reflect that #branch! doesn't check out.
  • Loading branch information...
commit badcb30c3ea2f00dd79059261723b7aeffe8a7cb 2 parents 96f1120 + ab27c1e
@benhoskings authored
Showing with 33 additions and 5 deletions.
  1. +4 −3 lib/babushka/git_repo.rb
  2. +29 −2 spec/babushka/git_repo_spec.rb
View
7 lib/babushka/git_repo.rb
@@ -235,9 +235,10 @@ def clone! from
}
end
- # Create a new local branch called +branch+, switching to it.
- def branch! branch
- repo_shell("git branch '#{branch}'")
+ # Create a new local branch called +branch+ with +ref+ (defaulting to
+ # HEAD) as its tip.
+ def branch! branch, ref=nil
+ repo_shell("git branch '#{branch}' '#{ref || "HEAD"}'")
end
# Create a new local tracking branch for +branch+, which should be specified
View
31 spec/babushka/git_repo_spec.rb
@@ -462,13 +462,40 @@ 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 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
+ it "should not have checked out the branch" do
+ 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
Please sign in to comment.
Something went wrong with that request. Please try again.