Module: Toolshed::Git

Included in:
Base, Github
Defined in:
lib/toolshed/git/git.rb,
lib/toolshed/git/github.rb

Defined Under Namespace

Classes: Base, GitValidator, Github

Constant Summary collapse

DEFAULT_GIT_TOOL =
'github'
DEFAULT_BRANCH_FROM =
'master'

Instance Method Summary collapse

Instance Method Details

#branch_nameObject



6
7
8
9
# File 'lib/toolshed/git/git.rb', line 6

def branch_name
  # branch information
  branch_name = `git rev-parse --abbrev-ref HEAD`.strip
end

#branch_name_from_id(id) ⇒ Object



15
16
17
# File 'lib/toolshed/git/git.rb', line 15

def branch_name_from_id(id)
  branch_name = `git branch | grep \"#{id}\"`.gsub("*", "").strip
end

#branched_fromObject



11
12
13
# File 'lib/toolshed/git/git.rb', line 11

def branched_from
  branched_from = `git rev-parse --abbrev-ref --symbolic-full-name @{u}`.split('/')[-1].strip
end

#checkout(branch_name) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/toolshed/git/git.rb', line 19

def checkout(branch_name)
  branch_name = Toolshed::Git::Base.branch_name_from_id(branch_name)
  Toolshed::Base.wait_for_command("git checkout #{branch_name} #{Toolshed::Client.git_quiet}")

  unless (Toolshed::Git::Base.git_submodule_command.empty?)
    Toolshed::Base.wait_for_command(Toolshed::Git::Base.git_submodule_command)
  end

  branch_name
end

#clean_branch_name(branch_name) ⇒ Object



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

def clean_branch_name(branch_name)
  branch_name.strip.downcase.tr(" ", "_").gsub("&", "").gsub("/", "_").gsub(".", "_").gsub("'", "").gsub("__", "_").gsub(":", "").gsub(",", "")
end

#delete(branch_name) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/toolshed/git/git.rb', line 30

def delete(branch_name)
  branch_name = Toolshed::Git::Base.branch_name_from_id(branch_name)

  # if delete your current branch checkout master so it can be deleted
  if (branch_name == Toolshed::Git::Base.branch_name)
    Toolshed::Git::Base.checkout('master')
  end

  Toolshed::Base.wait_for_command("git push #{Toolshed::Client.push_to_remote_name} :#{branch_name}; git branch -D #{branch_name}")

  branch_name
end

#git_submodule_commandObject



43
44
45
46
47
48
49
50
# File 'lib/toolshed/git/git.rb', line 43

def git_submodule_command
  git_submodule_command = ''
  if (Toolshed::Client.use_git_submodules)
    git_submodule_command = "git submodule update #{Toolshed::Client.git_quiet}"
  end

  git_submodule_command
end

#push(options = {}) ⇒ Object



56
57
58
59
60
61
62
63
# File 'lib/toolshed/git/git.rb', line 56

def push(options = {})
  branch_name = (options.has_key?(:branch_name)) ? Toolshed::Git::Base.branch_name_from_id(options[:branch_name]) : Toolshed::Git::Base.branch_name
  force_command = (options.has_key?(:force_command)) ? '--force' : ''

  Toolshed::Base.wait_for_command("git push #{Toolshed::Client.push_to_remote_name} #{branch_name} #{force_command}")

  branch_name
end