Module: GitSwitchBranch
- Defined in:
- lib/git_switch_branch.rb,
lib/git_switch_branch/changes.rb,
lib/git_switch_branch/version.rb
Constant Summary collapse
- GSB_APP_DATA_DIR =
'.git-switch-branch'
- VERSION =
"0.1.2"
Instance Attribute Summary collapse
-
#git ⇒ Object
Returns the value of attribute git.
-
#repo_changes_path ⇒ Object
Returns the value of attribute repo_changes_path.
Class Method Summary collapse
- .check_changes ⇒ Object
- .find_and_checkout_branch(string) ⇒ Object
- .initialize ⇒ Object
- .patch_path ⇒ Object
- .restore_changes ⇒ Object
- .save_changes ⇒ Object
- .show_changes ⇒ Object
- .show_usage ⇒ Object
- .show_version ⇒ Object
Instance Attribute Details
#git ⇒ Object
Returns the value of attribute git.
15 16 17 |
# File 'lib/git_switch_branch.rb', line 15 def git @git end |
#repo_changes_path ⇒ Object
Returns the value of attribute repo_changes_path.
15 16 17 |
# File 'lib/git_switch_branch.rb', line 15 def repo_changes_path @repo_changes_path end |
Class Method Details
.check_changes ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/git_switch_branch/changes.rb', line 29 def self.check_changes if saved_changes? puts "This branch has saved changes.".green else puts "This branch has no saved changes.".green end end |
.find_and_checkout_branch(string) ⇒ Object
23 24 25 26 |
# File 'lib/git_switch_branch.rb', line 23 def self.find_and_checkout_branch(string) initialize checkout select_branch(string) end |
.initialize ⇒ Object
17 18 19 20 21 |
# File 'lib/git_switch_branch.rb', line 17 def self.initialize @git = Git.open(Dir.pwd) current_dir = File.basename(Dir.getwd) @repo_changes_path = File.join(ENV['HOME'], GSB_APP_DATA_DIR, current_dir) end |
.patch_path ⇒ Object
37 38 39 |
# File 'lib/git_switch_branch.rb', line 37 def self.patch_path File.join(@repo_changes_path, @git.current_branch) end |
.restore_changes ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/git_switch_branch/changes.rb', line 17 def self.restore_changes return unless saved_changes? puts "Restoring changes...".green if apply_patch File.delete(patch_path) @git.reset else puts "Failed to restore saved changes!" puts "Please check #{patch_path}" end end |
.save_changes ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/git_switch_branch/changes.rb', line 6 def self.save_changes if saved_changes? puts "This branch already has saved changes.".red elsif uncommitted_changes? stash_uncommitted_changes save_stash_to_patch else puts "No uncommitted changes to save.".green end end |
.show_changes ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/git_switch_branch/changes.rb', line 37 def self.show_changes if saved_changes? system "cat #{patch_path} | less" else puts "No saved changes found for this branch at #{patch_path})" end end |
.show_usage ⇒ Object
32 33 34 35 |
# File 'lib/git_switch_branch.rb', line 32 def self.show_usage puts "git_switch_branch #{GitSwitchBranch::VERSION}\n\n" puts "Usage: gsb <branchname_or_part_of_branchname>" end |
.show_version ⇒ Object
28 29 30 |
# File 'lib/git_switch_branch.rb', line 28 def self.show_version puts GitSwitchBranch::VERSION end |