From 98fdaf72f58545dad6e9f192f291beeca6e3eced Mon Sep 17 00:00:00 2001 From: Christian Romney Date: Tue, 15 Jul 2008 15:48:14 -0400 Subject: [PATCH] Added branch support for Git. Set branch name in cruise_config.rb project.source_control.branch = 'foo' --- lib/source_control/git.rb | 19 ++++++++++--------- test/unit/source_control/git_test.rb | 12 ++++++++++++ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/lib/source_control/git.rb b/lib/source_control/git.rb index 0dfc88b..f9bbebb 100644 --- a/lib/source_control/git.rb +++ b/lib/source_control/git.rb @@ -2,8 +2,8 @@ module SourceControl class Git < AbstractAdapter - attr_accessor :repository - + attr_accessor :repository, :branch + def initialize(options) options = options.dup @path = options.delete(:path) || "." @@ -29,6 +29,10 @@ module SourceControl rescue EOFError end end + + unless @branch.eql?('master') + git("checkout", ['--track', '-b', @branch, "origin/#{@branch}"]) + end if revision git("reset", ['--hard', revision.number]) @@ -42,7 +46,7 @@ module SourceControl def latest_revision load_new_changesets_from_origin - git_output = git('log', ['-1', '--pretty=raw', 'origin/master']) + git_output = git('log', ['-1', '--pretty=raw', "origin/#{@branch}"]) Git::LogParser.new.parse(git_output).first end @@ -74,18 +78,15 @@ module SourceControl def new_revisions load_new_changesets_from_origin - git_output = git('log', ['--pretty=raw', 'HEAD..origin/master']) + git_output = git('log', ['--pretty=raw', "HEAD..origin/#{@branch}"]) Git::LogParser.new.parse(git_output) end def git(operation, arguments, options = {}, &block) command = ["git-#{operation}"] + arguments.compact -# TODO: figure out how to handle the same thing with git -# command << "--non-interactive" unless @interactive - + # TODO: figure out how to handle the same thing with git + # command << "--non-interactive" unless @interactive execute_in_local_copy(command, options, &block) end - end - end \ No newline at end of file diff --git a/test/unit/source_control/git_test.rb b/test/unit/source_control/git_test.rb index 955efce..5a8c767 100644 --- a/test/unit/source_control/git_test.rb +++ b/test/unit/source_control/git_test.rb @@ -14,6 +14,18 @@ class SourceControl::GitTest < Test::Unit::TestCase git.checkout(Git::Revision.new('5460c9ea8872745629918986df7238871f4135ae', "me", Time.at(0))) end end + + def test_checkout_with_branch_and_revision + in_sandbox do + branch = 'mybranch' + git = new_git(:repository => "git:/my_repo", :branch => branch) + git.expects(:git).with("clone", ["git:/my_repo", '.'], + :execute_in_current_directory => false) + git.expects(:git).with("checkout", ['--track', '-b', branch, "origin/#{branch}"]) + git.expects(:git).with("reset", ['--hard', '5460c9ea8872745629918986df7238871f4135ae']) + git.checkout(Git::Revision.new('5460c9ea8872745629918986df7238871f4135ae', "me", Time.at(0))) + end + end def test_update in_sandbox do -- 1.5.6.1