Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Create branch if it does not exist

  • Loading branch information...
commit 0bb015e2bf124b94093256339db535eb19650873 1 parent 56a91e7
@bkeepers authored
Showing with 23 additions and 5 deletions.
  1. +8 −2 lib/adapter/git.rb
  2. +15 −3 spec/git_spec.rb
View
10 lib/adapter/git.rb
@@ -4,8 +4,12 @@
module Adapter
module Git
+ def branch
+ options[:branch] || 'master'
+ end
+
def head
- client.get_head(options[:branch] || 'master')
+ client.get_head(branch)
end
def key?(key)
@@ -58,7 +62,9 @@ def commit(message)
yield index
- index.commit(message, Array(commit))
+ sha = index.commit(message, Array(commit))
+
+ client.update_ref(branch, sha) unless head
end
end
View
18 spec/git_spec.rb
@@ -2,12 +2,24 @@
require 'grit'
describe "Git adapter" do
- let(:adapter) { Adapter[:git].new(client) }
- let(:client) { Grit::Repo.init(File.expand_path('../test-repo', __FILE__)) }
+ let(:repo_dir) { File.expand_path('../test-repo', __FILE__) }
+ let(:adapter) { Adapter[:git].new(client) }
+ let(:client) { Grit::Repo.init(repo_dir) }
before do
- adapter.clear
+ FileUtils.rm_rf(repo_dir)
+
+ # Some adapter specs don't pass if there is not at least one commit in the
+ # repo since the git adapter short-circuits the key marshalling if there
+ # are no commits.
+ adapter.set('specs', 'running')
end
it_should_behave_like 'an adapter'
+
+ it 'should create a branch when it does not exist' do
+ adapter.options[:branch] = 'foobar'
+ adapter.set('foo', 'bar')
+ client.get_head('foobar').should_not be_nil
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.