Class: GitJump::Action

Inherits:
Object
  • Object
show all
Defined in:
lib/git_jump/action.rb

Instance Method Summary collapse

Constructor Details

#initialize(repository_path) ⇒ Action

Returns a new instance of Action.



5
6
7
8
# File 'lib/git_jump/action.rb', line 5

def initialize(repository_path)
  @repository_path = repository_path
  # @db = setup_database
end

Instance Method Details

#add(branch_name) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/git_jump/action.rb', line 10

def add(branch_name)
  project_name = File.basename(Dir.pwd)

  puts "GitJump::Action#add project_name: #{project_name}"

  # @db.execute(
  #   'INSERT INTO branches (project_name, branch_name) VALUES (?, ?)',
  #   [project_name, branch_name]
  # )

  puts "Branch '#{branch_name}' added for project '#{project_name}'"
end

#toggleObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/git_jump/action.rb', line 23

def toggle
  project_name = File.basename(Dir.pwd)

  branches = @db.execute(
    "SELECT branch_name FROM branches WHERE project_name = ?",
    [project_name]
  ).map(&:first)

  if branches.empty?
    puts "No branches found for project '#{project_name}'"
    return
  end

  current_branch = `git branch --show-current`.strip
  next_branch = branches[(branches.index(current_branch) || -1) + 1] || branches.first

  system("git checkout #{next_branch}")
  puts "Switched to branch '#{next_branch}'"
end