Skip to content

Commit

Permalink
Merge pull request #2 from jusleg/use-open3
Browse files Browse the repository at this point in the history
Use open3
  • Loading branch information
jusleg authored Mar 3, 2020
2 parents ab932f8 + b041b2b commit 2cab81a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# gitgud ![gitgud badge](https://img.shields.io/badge/gitgud%3F-good-brightgreen)
# gitgud ![gitgud badge](https://img.shields.io/badge/gitgud%3F-good-brightgreen) [![Gem Version](https://badge.fury.io/rb/gitgud.svg)](https://badge.fury.io/rb/gitgud)

When things go wrong, you need to `gitgud`. `gitgud` acts just like `git`, but gives you superpowers when trying to `git push`. It will attempt to `git push` until it succeeds.

![gitgud](https://user-images.githubusercontent.com/4406751/75472054-f3c92680-5960-11ea-9eaa-eff24eb4dfe4.gif)
![success after multiple retries](https://user-images.githubusercontent.com/4406751/75736774-1c884d80-5ccc-11ea-9e2c-5436937d38ed.gif)


## `gitgud` is the new `git`
Expand Down
18 changes: 15 additions & 3 deletions bin/gitgud
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
#!/usr/bin/env ruby

require 'cli/ui'
require 'open3'

def try_to_push_this_thing(spinner)
counter = 1
while !system('git', 'push', *ARGV)
while counter <= 20
spinner.update_title(spinner_title(counter))
counter += 1

output, status = Open3.capture2e('git', 'push', *ARGV)

if status.success?
return spinner.update_title("Successfully git pushed")
elsif !output.match?(/remote: Internal Server Error\sEverything up-to-date/)
spinner.update_title("Encountered error while git pushing\n#{output}")
return :task_failed
end
end
spinner.update_title('Successfully git pushed')

spinner.update_title("Unsuccessful after 20 attemps")
:task_failed
end

def spinner_title(attempt_number = 1)
Expand All @@ -21,7 +33,7 @@ end

def plz_push_my_thing_on_git_thx_k_bye
CLI::UI::StdoutRouter.enable
spin_group = CLI::UI::SpinGroup.new
spin_group = CLI::UI::SpinGroup.new(auto_debrief: false)
spin_group.add(spinner_title) { |spinner| try_to_push_this_thing(spinner) }
spin_group.wait
end
Expand Down

0 comments on commit 2cab81a

Please sign in to comment.