Module: Atlassian::Stash::Git

Defined in:
lib/atlassian/stash/git.rb

Constant Summary collapse

DEFAULT_REMOTE =
"origin"

Instance Method Summary collapse

Instance Method Details

#create_git_aliasObject



48
49
50
# File 'lib/atlassian/stash/git.rb', line 48

def create_git_alias
  %x(git config --global alias.create-pull-request "\!sh -c 'stash pull-request \\$0'")
end

#ensure_within_git!Object



40
41
42
43
44
45
46
# File 'lib/atlassian/stash/git.rb', line 40

def ensure_within_git!
  if is_in_git_repository?
    yield
  else
    raise "fatal: Not a git repository"
  end
end

#get_branchesObject



13
14
15
# File 'lib/atlassian/stash/git.rb', line 13

def get_branches()
  %x{git branch -a}
end

#get_current_branchObject



9
10
11
# File 'lib/atlassian/stash/git.rb', line 9

def get_current_branch
  %x(git symbolic-ref HEAD)[/refs\/heads\/(.*)/, 1]
end

#get_remote_url(remote = nil) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/atlassian/stash/git.rb', line 29

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

#get_remotesObject



25
26
27
# File 'lib/atlassian/stash/git.rb', line 25

def get_remotes
  %x(git remote -v)
end

#get_repo_root_directoryObject



52
53
54
# File 'lib/atlassian/stash/git.rb', line 52

def get_repo_root_directory
  %x(git rev-parse --show-toplevel)
end

#is_branch?(match) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/atlassian/stash/git.rb', line 17

def is_branch?(match)
  not get_branches.split().select{|x| x == match}.empty?
end

#is_in_git_repository?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/atlassian/stash/git.rb', line 21

def is_in_git_repository?
  system('git rev-parse')
end