Skip to content

Commit ba8a413

Browse files
kokeschacon
authored andcommitted
Added branch checking methods
Signed-off-by: Scott Chacon <[email protected]>
1 parent 36fb3cd commit ba8a413

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

lib/git/base.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,24 @@ def branches
189189
def branch(branch_name = 'master')
190190
Git::Branch.new(self, branch_name)
191191
end
192+
193+
# returns +true+ if the branch exists locally
194+
def is_local_branch?(branch)
195+
branch_names = self.branches.local.map {|b| b.name}
196+
branch_names.include?(branch)
197+
end
198+
199+
# returns +true+ if the branch exists remotely
200+
def is_remote_branch?(branch)
201+
branch_names = self.branches.local.map {|b| b.name}
202+
branch_names.include?(branch)
203+
end
204+
205+
# returns +true+ if the branch exists
206+
def is_branch?(branch)
207+
branch_names = self.branches.map {|b| b.name}
208+
branch_names.include?(branch)
209+
end
192210

193211
# returns a Git::Remote object
194212
def remote(remote_name = 'origin')

0 commit comments

Comments
 (0)