Skip to content
This repository has been archived by the owner on Dec 24, 2019. It is now read-only.

Commit

Permalink
Merge branch 'git-branch' -- add a 'ref' param, and update specs & do…
Browse files Browse the repository at this point in the history
…cs to reflect that #branch! doesn't check out.
  • Loading branch information
benhoskings committed Nov 25, 2012
2 parents 96f1120 + ab27c1e commit badcb30
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
7 changes: 4 additions & 3 deletions lib/babushka/git_repo.rb
Expand Up @@ -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
Expand Down
31 changes: 29 additions & 2 deletions spec/babushka/git_repo_spec.rb
Expand Up @@ -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

Expand Down

0 comments on commit badcb30

Please sign in to comment.