Class: Repository::Sequencer
- Inherits:
-
Object
- Object
- Repository::Sequencer
- Defined in:
- lib/repository/sequencer.rb
Constant Summary collapse
- UNSAFE_MESSAGE =
"You seem to have moved HEAD. Not rewinding, check your HEAD!"
Instance Method Summary collapse
- #abort ⇒ Object
- #drop_command ⇒ Object
- #dump ⇒ Object
- #get_option(name) ⇒ Object
-
#initialize(repository) ⇒ Sequencer
constructor
A new instance of Sequencer.
- #load ⇒ Object
- #next_command ⇒ Object
- #pick(commit) ⇒ Object
- #quit ⇒ Object
- #revert(commit) ⇒ Object
- #start(options) ⇒ Object
Constructor Details
#initialize(repository) ⇒ Sequencer
Returns a new instance of Sequencer.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/repository/sequencer.rb', line 11 def initialize(repository) @repo = repository @pathname = repository.git_path.join("sequencer") @abort_path = @pathname.join("abort-safety") @head_path = @pathname.join("head") @todo_path = @pathname.join("todo") @config = Config.new(@pathname.join("opts")) @todo_file = nil @commands = [] end |
Instance Method Details
#abort ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/repository/sequencer.rb', line 82 def abort head_oid = File.read(@head_path).strip expected = File.read(@abort_path).strip actual = @repo.refs.read_head quit raise UNSAFE_MESSAGE unless actual == expected @repo.hard_reset(head_oid) orig_head = @repo.refs.update_head(head_oid) @repo.refs.update_ref(Refs::ORIG_HEAD, orig_head) end |
#drop_command ⇒ Object
53 54 55 56 |
# File 'lib/repository/sequencer.rb', line 53 def drop_command @commands.shift write_file(@abort_path, @repo.refs.read_head) end |
#dump ⇒ Object
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/repository/sequencer.rb', line 71 def dump return unless @todo_file @commands.each do |action, commit| short = @repo.database.short_oid(commit.oid) @todo_file.write("#{ action } #{ short } #{ commit.title_line }") end @todo_file.commit end |
#get_option(name) ⇒ Object
36 37 38 39 |
# File 'lib/repository/sequencer.rb', line 36 def get_option(name) @config.open @config.get(["options", name]) end |
#load ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/repository/sequencer.rb', line 58 def load open_todo_file return unless File.file?(@todo_path) @commands = File.read(@todo_path).lines.map do |line| action, oid, _ = /^(\S+) (\S+) (.*)$/.match(line).captures oids = @repo.database.prefix_match(oid) commit = @repo.database.load(oids.first) [action.to_sym, commit] end end |
#next_command ⇒ Object
49 50 51 |
# File 'lib/repository/sequencer.rb', line 49 def next_command @commands.first end |
#pick(commit) ⇒ Object
41 42 43 |
# File 'lib/repository/sequencer.rb', line 41 def pick(commit) @commands.push([:pick, commit]) end |
#quit ⇒ Object
96 97 98 |
# File 'lib/repository/sequencer.rb', line 96 def quit FileUtils.rm_rf(@pathname) end |
#revert(commit) ⇒ Object
45 46 47 |
# File 'lib/repository/sequencer.rb', line 45 def revert(commit) @commands.push([:revert, commit]) end |
#start(options) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/repository/sequencer.rb', line 22 def start() Dir.mkdir(@pathname) head_oid = @repo.refs.read_head write_file(@head_path, head_oid) write_file(@abort_path, head_oid) @config.open_for_update .each { |key, value| @config.set(["options", key], value) } @config.save open_todo_file end |