Skip to content

Instantly share code, notes, and snippets.

@zed-0xff
Last active April 7, 2020 17:22
Show Gist options
  • Save zed-0xff/7e4dd2764269cb9d095af3bd531c2d08 to your computer and use it in GitHub Desktop.
Save zed-0xff/7e4dd2764269cb9d095af3bd531c2d08 to your computer and use it in GitHub Desktop.
RimWorld: convert each record from a mods list to a separate commit
#!/usr/bin/env ruby
# a code for an article at https://www.reddit.com/r/RimWorld/comments/fwoi36/using_bisection_power_of_git_to_identify_a_buggy/
ORIG_CONFIG_FNAME = "ModsConfig.xml.orig"
CONFIG_FNAME = "ModsConfig.xml"
ALWAYS_ADD = []
ALWAYS_ADD << 'brrainz.harmony'
ALWAYS_ADD << 'ludeon.rimworld'
ALWAYS_ADD << 'ludeon.rimworld.royalty'
ALWAYS_ADD << 'unlimitedhugs.hugslib'
lines = File.readlines(ORIG_CONFIG_FNAME)
def produce_config lines, allowed_mods
mods = []
data = ""
lines.each do |line|
if line['<li>']
if allowed_mods.any?{ |x| line[x] }
data << line
else
mods << line
end
else
data << line
end
end
[data, mods]
end
system "git init ."
system "git config user.email foo@foo"
system "git config user.name foo"
add_mods = []
msg = nil
loop do
config, mods = produce_config(lines, ALWAYS_ADD + add_mods)
File.write(CONFIG_FNAME, config)
if add_mods.empty?
system "git add #{CONFIG_FNAME}"
msg = "init"
else
msg = "add #{add_mods.last.sub('<li>','').sub('</li>','').strip}"
end
system "git commit -am '#{msg}'"
raise unless $?.success?
puts msg
break if mods.empty?
add_mods << mods.first
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment