| |   |
| 1 | 1 | class SCM::Git::Branch < SCM::Git::CommandProxyBase |
| 2 | 2 | def [](name) |
| 3 | | SCM::Git::BranchProxy.new(@base, self, name) |
| 3 | SCM::Git::Branch::Proxy.new(@base, self, name) |
| 4 | 4 | end |
| 5 | 5 | |
| 6 | 6 | def create_and_switch(name) |
| … | … | |
| 29 | 29 | result |
| 30 | 30 | end |
| 31 | 31 | |
| 32 | def all_for_local_or_remote(side) |
| 33 | list(side).map do |branch_params| |
| 34 | BranchProxy.new(@base, self, branch_params[:name], :current => branch_params[:default], :local => (side==:local)) |
| 35 | end |
| 36 | end |
| 37 | |
| 32 | 38 | def all(which = [:local, :remote]) |
| 33 | 39 | branches = [] |
| 34 | 40 | [which].flatten.each do |side| |
| 35 | | branches.concat list(which).map { |branch_params| |
| 36 | | next if branch_params[:name] == "(no branch)" |
| 37 | | SCM::Git::BranchProxy.new(@base, self, branch_params[:name], :current => branch_params[:default], :local => (side==:local)) |
| 38 | | } |
| 41 | branches.concat all_for_local_or_remote(side) |
| 39 | 42 | end |
| 40 | 43 | |
| 41 | 44 | branches.compact |
| … | … | |
| 117 | 117 | end |
| 118 | 118 | { :outcome => outcome, :output => output, :remote => remote, :branch => branch } |
| 119 | 119 | end |
| 120 | | end |
| 121 | | |
| 122 | | class SCM::Git::BranchProxy |
| 123 | | attr_reader :name |
| 124 | | |
| 125 | | def initialize(base, parent, name, options = {}) |
| 126 | | @base = base |
| 127 | | @parent = parent |
| 128 | | @name = name |
| 129 | | @current = options[:current] |
| 130 | | @local = options[:local] |
| 131 | | end |
| 132 | 120 | |
| 133 | | def local? |
| 134 | | @local |
| 135 | | end |
| 121 | class BranchProxy |
| 122 | attr_reader :name |
| 136 | 123 | |
| 137 | | def current? |
| 138 | | @current |
| 139 | | end |
| 124 | def initialize(base, parent, name, options = {}) |
| 125 | @base = base |
| 126 | @parent = parent |
| 127 | @name = name |
| 128 | @current = options[:current] |
| 129 | @local = options[:local] |
| 130 | end |
| 140 | 131 | |
| 141 | | def remote? |
| 142 | | ! @local |
| 143 | | end |
| 132 | def local? |
| 133 | @local |
| 134 | end |
| 144 | 135 | |
| 145 | | def default? |
| 146 | | raise "implement me" |
| 147 | | end |
| 136 | def current? |
| 137 | @current |
| 138 | end |
| 148 | 139 | |
| 149 | | def remote |
| 150 | | @base.config["branch.#{name}.remote"] |
| 151 | | end |
| 140 | def remote? |
| 141 | ! @local |
| 142 | end |
| 152 | 143 | |
| 153 | | def remote=(value) |
| 154 | | @base.config["branch.#{name}.remote"] = value |
| 155 | | end |
| 144 | def default? |
| 145 | raise "implement me" |
| 146 | end |
| 156 | 147 | |
| 157 | | def merge |
| 158 | | @base.config["branch.#{name}.merge"] |
| 159 | | end |
| 148 | def remote(reload = false) |
| 149 | @remote = nil if reload |
| 150 | @remote ||= @base.config["branch.#{name}.remote"] |
| 151 | end |
| 160 | 152 | |
| 161 | | def merge=(value) |
| 162 | | @base.config["branch.#{name}.merge"] = value |
| 153 | def remote=(value) |
| 154 | @remote = nil |
| 155 | @base.config["branch.#{name}.remote"] = value |
| 156 | end |
| 157 | |
| 158 | def merge(reload = false) |
| 159 | @merge = nil if (reload) |
| 160 | @merge ||= @base.config["branch.#{name}.merge"] |
| 161 | end |
| 162 | |
| 163 | def merge=(value) |
| 164 | @merge = nil |
| 165 | @base.config["branch.#{name}.merge"] = value |
| 166 | end |
| 163 | 167 | end |
| 164 | | end |
| 168 | end |
| 169 | |
| toggle raw diff |
--- a/Support/lib/commands/branch.rb
+++ b/Support/lib/commands/branch.rb
@@ -1,6 +1,6 @@
class SCM::Git::Branch < SCM::Git::CommandProxyBase
def [](name)
- SCM::Git::BranchProxy.new(@base, self, name)
+ SCM::Git::Branch::Proxy.new(@base, self, name)
end
def create_and_switch(name)
@@ -29,13 +29,16 @@ class SCM::Git::Branch < SCM::Git::CommandProxyBase
result
end
+ def all_for_local_or_remote(side)
+ list(side).map do |branch_params|
+ BranchProxy.new(@base, self, branch_params[:name], :current => branch_params[:default], :local => (side==:local))
+ end
+ end
+
def all(which = [:local, :remote])
branches = []
[which].flatten.each do |side|
- branches.concat list(which).map { |branch_params|
- next if branch_params[:name] == "(no branch)"
- SCM::Git::BranchProxy.new(@base, self, branch_params[:name], :current => branch_params[:default], :local => (side==:local))
- }
+ branches.concat all_for_local_or_remote(side)
end
branches.compact
@@ -114,48 +117,53 @@ class SCM::Git::Branch < SCM::Git::CommandProxyBase
end
{ :outcome => outcome, :output => output, :remote => remote, :branch => branch }
end
-end
-
-class SCM::Git::BranchProxy
- attr_reader :name
-
- def initialize(base, parent, name, options = {})
- @base = base
- @parent = parent
- @name = name
- @current = options[:current]
- @local = options[:local]
- end
- def local?
- @local
- end
+ class BranchProxy
+ attr_reader :name
- def current?
- @current
- end
+ def initialize(base, parent, name, options = {})
+ @base = base
+ @parent = parent
+ @name = name
+ @current = options[:current]
+ @local = options[:local]
+ end
- def remote?
- ! @local
- end
+ def local?
+ @local
+ end
- def default?
- raise "implement me"
- end
+ def current?
+ @current
+ end
- def remote
- @base.config["branch.#{name}.remote"]
- end
+ def remote?
+ ! @local
+ end
- def remote=(value)
- @base.config["branch.#{name}.remote"] = value
- end
+ def default?
+ raise "implement me"
+ end
- def merge
- @base.config["branch.#{name}.merge"]
- end
+ def remote(reload = false)
+ @remote = nil if reload
+ @remote ||= @base.config["branch.#{name}.remote"]
+ end
- def merge=(value)
- @base.config["branch.#{name}.merge"] = value
+ def remote=(value)
+ @remote = nil
+ @base.config["branch.#{name}.remote"] = value
+ end
+
+ def merge(reload = false)
+ @merge = nil if (reload)
+ @merge ||= @base.config["branch.#{name}.merge"]
+ end
+
+ def merge=(value)
+ @merge = nil
+ @base.config["branch.#{name}.merge"] = value
+ end
end
-end
\ No newline at end of file
+end
+ |
| |   |
| 5 | 5 | @git = Git.new |
| 6 | 6 | Git.reset_mock! |
| 7 | 7 | end |
| 8 | |
| 8 | 9 | include SpecHelpers |
| 9 | 10 | |
| 10 | 11 | it "should list ignore (no branch)" do |
| … | … | |
| 16 | 16 | |
| 17 | 17 | @git.branch.list_names.should == ["test_mod"] |
| 18 | 18 | end |
| 19 | |
| 20 | describe "listing branches" do |
| 21 | before(:each) do |
| 22 | Git.command_response["branch"] = <<EOF |
| 23 | * test_mod |
| 24 | master |
| 25 | EOF |
| 26 | Git.command_response["branch", "-r"] = <<EOF |
| 27 | origin/alpha |
| 28 | origin/test_mod |
| 29 | origin/master |
| 30 | EOF |
| 31 | end |
| 32 | |
| 33 | it "should return a list of branches" do |
| 34 | @git.branch.all.should have(5).branches |
| 35 | end |
| 36 | |
| 37 | it "should filter to the remote branches" do |
| 38 | @git.branch.all(:remote).should have(3).branches |
| 39 | end |
| 40 | |
| 41 | it "should filter to the local branches" do |
| 42 | @git.branch.all(:local).should have(2).branches |
| 43 | end |
| 44 | end |
| 19 | 45 | end |
| toggle raw diff |
--- a/Support/spec/lib/commands/branch_spec.rb
+++ b/Support/spec/lib/commands/branch_spec.rb
@@ -5,6 +5,7 @@ describe SCM::Git::Branch do
@git = Git.new
Git.reset_mock!
end
+
include SpecHelpers
it "should list ignore (no branch)" do
@@ -15,4 +16,30 @@ EOF
@git.branch.list_names.should == ["test_mod"]
end
+
+ describe "listing branches" do
+ before(:each) do
+ Git.command_response["branch"] = <<EOF
+* test_mod
+ master
+EOF
+ Git.command_response["branch", "-r"] = <<EOF
+ origin/alpha
+ origin/test_mod
+ origin/master
+EOF
+ end
+
+ it "should return a list of branches" do
+ @git.branch.all.should have(5).branches
+ end
+
+ it "should filter to the remote branches" do
+ @git.branch.all(:remote).should have(3).branches
+ end
+
+ it "should filter to the local branches" do
+ @git.branch.all(:local).should have(2).branches
+ end
+ end
end |