Skip to content

Instantly share code, notes, and snippets.

@rmehta
Last active July 19, 2017 12:23
Show Gist options
  • Save rmehta/9891726 to your computer and use it in GitHub Desktop.
Save rmehta/9891726 to your computer and use it in GitHub Desktop.
Git all
#!/usr/bin/env python2.7
import sys, os
import subprocess, commands
def main():
git = commands.getoutput('which git')
args = sys.argv[1:]
for folder in os.listdir("."):
if os.path.exists(os.path.join(folder, ".git")):
cwd = os.path.abspath(folder)
try:
if args[0]=="pull" or args[0]=="push":
branches = subprocess.check_output([git, 'branch', '--no-color'], cwd=cwd)
branch = filter(lambda d: d.startswith("*"), branches.split("\n"))[0].split(" ", 1)[1]
remote = subprocess.check_output([git, 'remote'], cwd=cwd).split("\n")
remote = "frappe" if "frappe" in remote else ("upstream" if "upstream" in remote else "origin")
print " ".join([git] + args + [remote, branch])
print subprocess.check_output([git] + args + [remote, branch], cwd=cwd)
else:
print " ".join([git] + sys.argv[1:])
print subprocess.check_output([git] + sys.argv[1:], cwd=cwd)
except subprocess.CalledProcessError, e:
print e.output
if __name__=="__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment