Class: Snaptoken::Commands::Diff

Inherits:
BaseCommand show all
Defined in:
lib/snaptoken/commands/diff.rb

Constant Summary

Constants inherited from BaseCommand

BaseCommand::ERROR_MSG

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseCommand

#current_or_latest_step, #current_step, inherited, #initialize, #latest_step, #needs!, #select_step, #step_path, #steps

Constructor Details

This class inherits a constructor from Snaptoken::Commands::BaseCommand

Class Method Details

.nameObject



2
3
4
# File 'lib/snaptoken/commands/diff.rb', line 2

def self.name
  "diff"
end

.summaryObject



6
7
8
# File 'lib/snaptoken/commands/diff.rb', line 6

def self.summary
  "Convert repo into a single file containing diffs for each step"
end

Instance Method Details

#runObject



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

def run
  needs! :config, :repo

  FileUtils.cd(File.join(@config[:path], "repo")) do
    patches = `git format-patch --stdout -p --no-signature --histogram --root master`
    File.open("../steps.diff", "w") do |f|
      step_num = 1
      patches.each_line do |line|
        if line =~ /^(From|Date|index)/
          # skip
        elsif line =~ /^Subject: \[[^\]]*\](.*)$/
          f << "\n" unless step_num == 1
          step = Snaptoken::Step.from_commit_msg(step_num, $1.strip)
          f << "~~~ step: #{step.commit_msg}\n"
          step_num += 1
        elsif line.chomp.length > 0
          f << line
        end
      end
    end
  end
end