lib/atlassian/stash/git.rb in atlassian-stash-0.3.1 vs lib/atlassian/stash/git.rb in atlassian-stash-0.3.2
- old
+ new
@@ -1,10 +1,13 @@
module Atlassian
module Stash
module Git
+
+ DEFAULT_REMOTE="origin"
+
def get_current_branch
%x(git symbolic-ref HEAD)[/refs\/heads\/(.*)/, 1]
end
def is_in_git_repository?
@@ -13,11 +16,17 @@
def get_remotes
%x(git remote -v)
end
- def get_remote_url(remote = 'origin')
- origin = get_remotes.split("\n").collect { |r| r.strip }.grep(/^#{remote}.*\(push\)$/).first
+ def get_remote_url(remote=nil)
+ remotes = get_remotes
+ return nil if remotes.empty?
+
+ remote = DEFAULT_REMOTE if remote.nil? || remote.empty?
+
+ origin = remotes.split("\n").collect { |r| r.strip }.grep(/^#{remote}.*\(push\)$/).first
+ return nil if origin.nil?
URI.extract(origin).first
end
def ensure_within_git!
if is_in_git_repository?