Class: Pomodoro::Commands::Commit

Inherits:
Command
  • Object
show all
Defined in:
lib/pomodoro/commands/commit.rb

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from Pomodoro::Commands::Command

Instance Method Details

#runObject


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/pomodoro/commands/commit.rb', line 17

def run
  ensure_today

  if with_active_task(self.config) do |active_task|
        tag = active_task.tags.find { |tag| tag.match(/^\d+$/) }
        body = [active_task.body, tag && "Closes ##{tag}"].compact.join(' ')
        # TODO: closes vs. mention only? Shall we use commit -v?
        commit_message = Shellwords.escape(body)
        arguments = [*@args, '-m', commit_message].join(' ')
        puts("#{t(:log_command, commit_message: commit_message)}\n\n")

        command("git commit #{arguments}")
     end
  else
    abort t(:no_task_in_progress) # TODO: raise NoTaskInProgress.
  end
end