From e1a5da7a55363b0f0a2b294a109f868eddcc6d0d Mon Sep 17 00:00:00 2001 From: Yossef Mendelssohn Date: Fri, 5 Oct 2012 02:04:17 -0400 Subject: [PATCH] Move master? from Config to Checkout It belongs with sha/changes/dirty?, and you know it. --- lib/boxen/checkout.rb | 4 ++++ lib/boxen/config.rb | 6 ------ test/boxen_checkout_test.rb | 8 ++++++++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/boxen/checkout.rb b/lib/boxen/checkout.rb index d7d9bdb..060d4b3 100644 --- a/lib/boxen/checkout.rb +++ b/lib/boxen/checkout.rb @@ -10,6 +10,10 @@ module Boxen Dir.chdir(config.repodir) { `git rev-parse HEAD`.strip } end + def master? + Dir.chdir(config.repodir) { `git symbolic-ref HEAD`.strip == 'refs/heads/master' } + end + def dirty? !changes.empty? end diff --git a/lib/boxen/config.rb b/lib/boxen/config.rb index 1be3be7..1cf8862 100644 --- a/lib/boxen/config.rb +++ b/lib/boxen/config.rb @@ -148,12 +148,6 @@ module Boxen @login = login end - # Is Boxen running on the `master` branch? - - def master? - `git symbolic-ref HEAD`.chomp == "refs/heads/master" - end - # A GitHub user's profile name. attr_accessor :name diff --git a/test/boxen_checkout_test.rb b/test/boxen_checkout_test.rb index 756ff30..ea7cea3 100644 --- a/test/boxen_checkout_test.rb +++ b/test/boxen_checkout_test.rb @@ -18,6 +18,14 @@ class BoxenCheckoutTest < Boxen::Test assert_equal sha, @checkout.sha end + def test_master? + @checkout.stubs(:"`").with("git symbolic-ref HEAD").returns("refs/heads/topic\n") + assert !@checkout.master? + + @checkout.stubs(:"`").with("git symbolic-ref HEAD").returns("refs/heads/master\n") + assert @checkout.master? + end + def test_changes changes = ' maybe a bunch of stuff happened ' @checkout.expects(:"`").with("git status --porcelain").returns(changes)