Skip to content

Commit

Permalink
write script
Browse files Browse the repository at this point in the history
  • Loading branch information
broothie committed Jul 13, 2022
1 parent b1c1ed3 commit 9c22ebc
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions script.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

CHARACTERS = ('0'..'9').to_a + ('a'..'f').to_a

def random_hex_char
CHARACTERS.sample
end

def random_short_sha
Array.new(7) { random_hex_char }.join
end

if __FILE__ == $0
counter = 0
loop do
attempt = counter + 1
short_sha = random_short_sha
puts "attempt #{attempt}, short sha is #{short_sha}" if (counter % 1000).zero?

message = "attempt #{attempt}: #{short_sha}"
output = `git commit --allow-empty -m '#{message}'`.chomp

if output == "[main #{short_sha}] #{message}"
puts "success! the lucky short sha is #{short_sha}"
break
else
`git reset --hard HEAD~`
end

counter += 1
end
end

0 comments on commit 9c22ebc

Please sign in to comment.