Class: Command::Rm

Inherits:
Base
  • Object
show all
Defined in:
lib/command/rm.rb

Constant Summary collapse

BOTH_CHANGED =
"staged content different from both the file and the HEAD"
INDEX_CHANGED =
"changes staged in the index"
WORKSPACE_CHANGED =
"local modifications"

Instance Attribute Summary

Attributes inherited from Base

#status

Instance Method Summary collapse

Methods inherited from Base

#execute, #initialize

Constructor Details

This class inherits a constructor from Command::Base

Instance Method Details

#define_optionsObject



13
14
15
16
17
# File 'lib/command/rm.rb', line 13

def define_options
  @parser.on("--cached")      { @options[:cached]    = true }
  @parser.on("-f", "--force") { @options[:force]     = true }
  @parser.on("-r")            { @options[:recursive] = true }
end

#runObject



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
# File 'lib/command/rm.rb', line 19

def run
  repo.index.load_for_update

  @head_oid     = repo.refs.read_head
  @inspector    = Repository::Inspector.new(repo)
  @uncommitted  = []
  @unstaged     = []
  @both_changed = []

  @args = @args.flat_map { |path| expand_path(path) }
               .map { |path| Pathname.new(path) }

  @args.each { |path| plan_removal(path) }
  exit_on_errors

  @args.each { |path| remove_file(path) }
  repo.index.write_updates

  exit 0

rescue => error
  repo.index.release_lock
  @stderr.puts "fatal: #{ error.message }"
  exit 128
end