Skip to content

Instantly share code, notes, and snippets.

@aoloe
Created May 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aoloe/302f79e01f078093306d to your computer and use it in GitHub Desktop.
Save aoloe/302f79e01f078093306d to your computer and use it in GitHub Desktop.
git status with dir from python
import os
from sh import git
def subDirPath (d):
return filter(os.path.isdir, [os.path.join(d,f) for f in os.listdir(d)])
curDir = os.getcwd()
curDir = "/home/ale/docs/src/"
for d in subDirPath(curDir) :
if os.path.isdir(os.path.join(d, ".git")) :
print(git("--git-dir="+os.path.join(d, ".git")+" --work-tree="+d+" status --porcelain"))
break
elif os.path.isdir(os.path.join(d, ".svn")) :
print("svn "+d)
"""
output:
RAN: '/usr/bin/git --git-dir=/home/ale/docs/src/scribus-manual-introduction/.git --work-tree=/home/ale/docs/src/scribus-manual-introduction status --porcelain'
STDOUT:
usage: git [--version] [--help] [-C <path>] [-c name=value]
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment