Module: Toolshed::Git
Defined Under Namespace
Classes: Base, GitValidator, Github
Constant Summary collapse
- DEFAULT_GIT_TOOL =
'github'
- DEFAULT_BRANCH_FROM =
'master'
Instance Method Summary collapse
- #branch_name ⇒ Object
- #branch_name_from_id(id) ⇒ Object
- #branched_from ⇒ Object
- #checkout(branch_name) ⇒ Object
- #clean_branch_name(branch_name) ⇒ Object
- #delete(branch_name) ⇒ Object
- #git_submodule_command ⇒ Object
- #push(options = {}) ⇒ Object
Instance Method Details
#branch_name ⇒ Object
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_from ⇒ Object
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_command ⇒ Object
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( = {}) branch_name = (.has_key?(:branch_name)) ? Toolshed::Git::Base.branch_name_from_id([:branch_name]) : Toolshed::Git::Base.branch_name force_command = (.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 |