Class: Discharger::SetupRunner::Commands::GitCommand

Inherits:
BaseCommand
  • Object
show all
Defined in:
lib/discharger/setup_runner/commands/git_command.rb

Instance Attribute Summary

Attributes inherited from BaseCommand

#app_root, #config, #logger

Instance Method Summary collapse

Methods inherited from BaseCommand

#initialize

Constructor Details

This class inherits a constructor from Discharger::SetupRunner::Commands::BaseCommand

Instance Method Details

#can_execute?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/discharger/setup_runner/commands/git_command.rb', line 35

def can_execute?
  File.directory?(File.join(app_root, ".git"))
end

#descriptionObject



39
40
41
# File 'lib/discharger/setup_runner/commands/git_command.rb', line 39

def description
  "Setup git configuration"
end

#executeObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/discharger/setup_runner/commands/git_command.rb', line 9

def execute
  log "Setting up git configuration"

  # Set up commit template if it exists
  commit_template = File.join(app_root, ".commit-template")
  if File.exist?(commit_template)
    system! "git config --local commit.template .commit-template"
    log "Git commit template configured"
  end

  # Set up git hooks if .githooks directory exists
  githooks_dir = File.join(app_root, ".githooks")
  if File.directory?(githooks_dir)
    system! "git config --local core.hooksPath .githooks"
    log "Git hooks path configured"
  end

  # Any other git config from the setup.yml
  if config.respond_to?(:git_config) && config.git_config
    config.git_config.each do |key, value|
      system! "git config --local #{key} '#{value}'"
      log "Set git config #{key}"
    end
  end
end