From a64de9b4aa471320f92031582bcac6ebab2b6799 Mon Sep 17 00:00:00 2001 From: Jan Bieron Date: Sat, 24 Oct 2015 19:32:27 +0200 Subject: [PATCH 1/2] commits.empty? check, shuffle once --- git-game | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/git-game b/git-game index 503eb61..8338cdf 100755 --- a/git-game +++ b/git-game @@ -55,12 +55,13 @@ system('clear') print_header puts "You're playing in a repo with #{commits.size} commits and #{committers.size}" -puts "distinct committers.\n\n" +puts "distinct committers:" committers.each do |committer| puts committer end +puts puts "Ready? PRESS ENTER TO START PLAYING (Ctrl-C to quit)" gets @@ -69,9 +70,15 @@ system('clear') # -- Game loop -- NUM_CHOICE = 4 +commits.shuffle! loop do - commit = commits.shuffle.pop + if commits.empty? + puts "There are no more commits left. You've beaten this repo!" + break + end + + commit = commits.pop message = commit[:message] author = commit[:author] From c6c0477bfa96b76c57b5c28789473ed2d05386dd Mon Sep 17 00:00:00 2001 From: Jan Bieron Date: Sat, 24 Oct 2015 19:41:18 +0200 Subject: [PATCH 2/2] propagate git errors --- git-game | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/git-game b/git-game index 8338cdf..f18007d 100755 --- a/git-game +++ b/git-game @@ -40,6 +40,10 @@ FIELD_DELIMITER = "|||" commit_format = ["%an", "%ar", "%B"].join(FIELD_DELIMITER) raw_commits = `git log --no-merges --pretty="#{COMMIT_DELIMITER}#{commit_format}" #{input if input}`.split("#{COMMIT_DELIMITER}") +if $?.exitstatus != 0 + exit $?.exitstatus +end + commits = [] raw_commits.each do |c| next if c.strip.empty?