Module: KKGit::RakeTasks

Defined in:
lib/kk/git/rake_tasks.rb

Overview

Rake integration: ‘require ’kk/git/rake_tasks’‘ to register tasks.

Notes:

  • These tasks do NOT exit/abort so they can be invoked by other tasks.

  • The generated message is stored in ‘ENV`.

Class Method Summary collapse

Class Method Details

.install!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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/kk/git/rake_tasks.rb', line 13

def self.install!
  extend Rake::DSL

  namespace :git do
    desc 'Show branch sync status (ahead/behind/clean)'
    task :status do
      s = KKGit::GitOps.status
      puts "Branch: #{s.branch} (#{s.remote})"
      puts "Working tree: #{s.clean ? 'clean' : 'dirty'}"
      puts "Ahead: #{s.ahead}, Behind: #{s.behind}"
      puts "Upstream: #{s.upstream_configured ? 'configured' : 'not set'}"
      puts 'Detached HEAD: yes' if s.detached
    end

    desc 'Pull and push without committing (sync unpushed or behind commits)'
    task :sync do
      remote = KKGit::GitOps.remote
      branch = KKGit::GitOps.branch
      s = KKGit::GitOps.status(remote: remote, branch: branch)

      if s.needs_sync?
        KKGit::GitOps.sync_with_remote!(remote, branch)
      else
        puts 'Already in sync with remote'
      end
    end

    desc 'Generate commit message from staged changes (Conventional Commits)'
    task :commit_message do
      msg = KKGit::CommitMessage.generate(mode: :staged)
      ENV['KK_GIT_COMMIT_MESSAGE'] = msg.to_s
      puts msg if msg
    end

    desc 'Generate commit message from working-tree changes (includes untracked)'
    task :commit_message_worktree do
      msg = KKGit::CommitMessage.generate(mode: :worktree)
      ENV['KK_GIT_COMMIT_MESSAGE'] = msg.to_s
      puts msg if msg
    end

    desc 'Generate commit message from staged + working-tree changes'
    task :auto_commit do
      msg = KKGit::CommitMessage.generate(mode: :all)
      ENV['KK_GIT_COMMIT_MESSAGE'] = msg.to_s
      puts msg if msg
    end

    desc 'Auto add/commit/pull/push (uses git:auto_commit)'
    task :auto_commit_push do
      generator = lambda do
        Rake::Task['git:auto_commit'].reenable
        Rake::Task['git:auto_commit'].invoke
        ENV['KK_GIT_COMMIT_MESSAGE'].to_s
      end

      KKGit::GitOps.auto_commit_push!(commit_message_generator: generator)
    end
  end
end