lib/legit.rb in legit-0.0.5 vs lib/legit.rb in legit-0.0.6

- old
+ new

@@ -15,22 +15,23 @@ system(command.join(' ')) end desc "catch-todos [TODO_FORMAT]", "Abort commit if any todos in TODO_FORMAT found" method_option :warn, :type => :boolean, :aliases => "-w", :desc => 'Warn and prompt the user to choose whether to abort the commit' + method_option :enable, :type => :boolean, :desc => 'Enable todo checking' + method_option :disable, :type => :boolean, :desc => 'Disable todo checking' def catch_todos(todo_format = "TODO") - system("git diff --staged | grep '^+' | grep #{todo_format}") - - if $?.success? - if options[:warn] - exit 1 unless positive_response?("[pre-commit hook] Found staged `#{todo_format}`s. Do you still want to continue?", :warning) + if options[:enable] + repo.config.delete('hooks.ignore-todos') + elsif options[:disable] + repo.config['hooks.ignore-todos'] = true + else + if repo.config['hooks.ignore-todos'] == 'true' + show("[pre-commit hook] ignoring todos. Re-enable with `legit catch-todos --enable`", :low_warning) else - show("[pre-commit hook] Aborting commit... found staged `#{todo_format}`s.", :warning) - exit 1 + run_catch_todos(todo_format) end - else - show("Success: No #{todo_format}s staged.", :success) end end desc "delete BRANCH", "Delete BRANCH both locally and remotely" def delete(branch_name) @@ -47,6 +48,25 @@ puts "Abort. #{branch_name} not deleted" end end end + private + def repo + @repo ||= Rugged::Repository.new('.') + end + + def run_catch_todos(todo_format) + system("git diff --staged | grep '^+' | grep #{todo_format}") + + if $?.success? + if options[:warn] + exit 1 unless positive_response?("[pre-commit hook] Found staged `#{todo_format}`s. Do you still want to continue?", :warning) + else + show("[pre-commit hook] Aborting commit... found staged `#{todo_format}`s.", :warning) + exit 1 + end + else + show("Success: No #{todo_format}s staged.", :success) + end + end end