class Gitl::SubCommand

Attributes

gitl_config[R]

Public Class Methods

new(argv) click to toggle source
Calls superclass method
# File lib/sub_command.rb, line 21
def initialize(argv)
  @yml = argv.option('config')
  if @yml.nil?
    @yml = 'Gitl.yml'
  end
  super
end
options() click to toggle source
Calls superclass method
# File lib/sub_command.rb, line 15
def self.options
  [
      ['--config=[Gitl.yml]', 'gitl配置, 默认为Gitl.yml'],
  ].concat(super)
end

Public Instance Methods

check_uncommit(g, project_name) click to toggle source
# File lib/sub_command.rb, line 92
def check_uncommit(g, project_name)
  changed = g.status.changed
  added = g.status.added
  deleted = g.status.deleted
  untracked = g.status.untracked

  if !changed.empty?
    alert = true
    puts "modified files:".red
    changed.each do |file, status|
      puts ("        M:        " << file).red
    end
  end

  if !added.empty?
    alert = true
    puts "added files:".red
    added.each do |file, status|
      puts ("        A:        " << file).red
    end
  end

  if !deleted.empty?
    alert = true
    puts "deleted files:".red
    deleted.each do |file, status|
      puts ("        D:        " << file).red
    end
  end

  if !untracked.empty?
    alert = true
    puts "untracked files:".red
    untracked.each do |file, status|
      puts ("        " << file).red
    end
  end

  if alert
    puts "exist uncommit files in current branch '#{g.current_branch}' for '#{project_name}'. ignore it? y/n "
    flag = STDIN.gets.chomp
    unless flag.downcase == "y"
      exit
    end
  end
end
run() click to toggle source
# File lib/sub_command.rb, line 33
def run
  workspace_path = "./"
  find_workspace = false;
  begin
    result = nil
    Dir.chdir(workspace_path) do
      result = Dir.glob('.gitl', File::FNM_DOTMATCH)
    end
    if result.length > 0
      find_workspace = true
      break
    else
      workspace_path = File.expand_path("../", workspace_path)
    end
  end while workspace_path.length > 0 && workspace_path != "/"

  if find_workspace
    Dir.chdir(workspace_path) do
      self.run_in_workspace()
    end
  else
    raise Error.new("Current path is not gitl workspace.")
  end
end
run_in_workspace() click to toggle source
# File lib/sub_command.rb, line 58
def run_in_workspace

end
save_workspace_config(workspace_config) click to toggle source
# File lib/sub_command.rb, line 84
def save_workspace_config(workspace_config)
  filename = '.gitl'
  # workspace_config_path = File.expand_path(filename, File.dirname(self.gitl_config.config_path))
  workspace_config_path = filename
  workspace_config.save(workspace_config_path)
  @workspace_config = workspace_config
end
validate!() click to toggle source
Calls superclass method
# File lib/sub_command.rb, line 29
def validate!
  super
end
workspace_config() click to toggle source
# File lib/sub_command.rb, line 71
def workspace_config
  if @workspace_config.nil?
    filename = '.gitl'
    # workspace_config_path = File.expand_path(filename, File.dirname(self.gitl_config.config_path))
    workspace_config_path = filename
    if !File.exist?(workspace_config_path)
      help! "workspace config not found. please run 'gitl start' first."
    end
    @workspace_config = WorkSpaceConfig.load_file(workspace_config_path)
  end
  @workspace_config
end