Skip to content

Instantly share code, notes, and snippets.

@simonwhitaker
Last active August 29, 2015 14:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simonwhitaker/e05c2f637170d51d06d0 to your computer and use it in GitHub Desktop.
Save simonwhitaker/e05c2f637170d51d06d0 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
#
# git-flip-flop: checks out two or more commits in a periodic cycle
#
# Save on your $PATH as git-flip-flop
#
# EXAMPLES
#
# Check out abc1234, then def5678, then abc1234, etc, with
# the default 2s between each checkout
#
# git-flip-flop abc1234 def5678
#
# Check out abc1234, then def5678, then abc1234, etc, with
# the 10s between each checkout
#
# git-flip-flop --interval=10 abc1234 def5678
#
# Check out abc1234, then master, then v1.0, then abc1234 etc
#
# git-flip-flop abc1234 master v1.0
#
# etc etc. You get the idea. :)
import argparse
import os
import sys
import time
parser = argparse.ArgumentParser(description='Flip between two or more revisions on a periodic cycle')
parser.add_argument('--interval', '-i', type=int, default=2, help='The interval in seconds between successive checkouts')
parser.add_argument('revisions', metavar='REV', nargs='+', help='The revisions to check out')
args = parser.parse_args()
if len(args.revisions) < 2:
print "You must supply two or more revisions to work with"
sys.exit(1)
revision_index = 0
while True:
revision = args.revisions[revision_index]
revision_index += 1
if revision_index >= len(args.revisions):
revision_index = 0
# git checkout revision
os.system('git checkout %s' % (revision))
time.sleep(args.interval)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment