Class: GitJump::Hooks::PostCheckout
- Inherits:
-
Object
- Object
- GitJump::Hooks::PostCheckout
- Defined in:
- lib/git_jump/hooks/post_checkout.rb
Overview
Post-checkout hook implementation
Instance Attribute Summary collapse
-
#repository_path ⇒ Object
readonly
Returns the value of attribute repository_path.
Instance Method Summary collapse
-
#initialize(repository_path) ⇒ PostCheckout
constructor
A new instance of PostCheckout.
- #run ⇒ Object
Constructor Details
#initialize(repository_path) ⇒ PostCheckout
Returns a new instance of PostCheckout.
9 10 11 |
# File 'lib/git_jump/hooks/post_checkout.rb', line 9 def initialize(repository_path) @repository_path = repository_path end |
Instance Attribute Details
#repository_path ⇒ Object (readonly)
Returns the value of attribute repository_path.
7 8 9 |
# File 'lib/git_jump/hooks/post_checkout.rb', line 7 def repository_path @repository_path end |
Instance Method Details
#run ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/git_jump/hooks/post_checkout.rb', line 13 def run repository = Repository.new(repository_path) config = Config.new return unless config.auto_track? database = Database.new(config.database_path) project = database.find_or_create_project( repository.project_path, repository.project_basename ) current_branch = repository.current_branch return unless current_branch && !current_branch.empty? database.add_branch(project["id"], current_branch) # Cleanup old branches if exceeded max total = database.count_branches(project["id"]) database.cleanup_old_branches(project["id"], config.max_branches) if total > config.max_branches database.close rescue StandardError # Silent fail in hooks to avoid interrupting git operations nil end |