#!/usr/bin/env python import os, random, subprocess, sys, time home = os.environ['HOME'] lock_files = [home + "/.git/index.lock", home + "/.git/master.lock"] for i in range(50): # 50 chances (about 5 seconds) had_to_wait = False for file in lock_files: if os.path.exists(file): print "Waiting for lock file to vanish..." time.sleep(.05 + random.random()*.1) had_to_wait = True break if not had_to_wait: p = subprocess.Popen(['git'] + sys.argv[1:]) sys.exit(p.wait()) sys.exit(1) # FAIL