From 9c22ebcc8890757942b05b91a866d4bfb46581c6 Mon Sep 17 00:00:00 2001 From: broothie Date: Wed, 13 Jul 2022 13:13:45 -0700 Subject: [PATCH] write script --- script.rb | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 script.rb diff --git a/script.rb b/script.rb new file mode 100644 index 0000000..961de2a --- /dev/null +++ b/script.rb @@ -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