[git-whatsnew] --porcelain + On n'affiche pas toujours les fichiers non trackés

This commit is contained in:
Vincent Le Gallic 2013-07-01 01:51:38 +02:00
parent 5765737e72
commit 4ca4ffd57d

View file

@ -20,18 +20,25 @@ class GitError(Exception):
Exception.__init__(self, msg)
def get_status():
"""Récupère le status du dépôt courant. Échoue si on n'est pas dans un dépôt git."""
proc = subprocess.Popen(["git", "status"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
def get_status(with_untracked_files=False):
"""Récupère le status du dépôt courant. Échoue si on n'est pas dans un dépôt git.
-b donne les informations de tracking, mais du coup il y a toujours un output, il faut vérifier si il est relevant"""
cmd = ["git", "status", "--porcelain", "-b"]
if not with_untracked_files:
cmd.append("--untracked-files=no")
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = proc.communicate()
if proc.returncode != 0:
raise GitError(err)
return out.decode("utf-8")
out = out.decode("utf-8")
return out
def get_status_silentfail():
def get_status_silentfail(with_untracked_files=False):
"""Récupère le status, mais ne renvoie rien si le ``git status`` est essentiellement vide."""
out = get_status()
if not u"nothing to commit (working directory clean)" in out:
out = get_status(with_untracked_files)
if all([len(l) == 0 or l.startswith(u"#") for l in out.split(u"\n")]) and not u"adhead" in out:
return u""
else:
return out
def get_repo():
@ -51,12 +58,13 @@ if __name__ == "__main__":
parser.add_argument("-f", "--from", action="store", type=str, dest="mail_from", help="Expéditeur du mail")
parser.add_argument("-t", "--to", action="store", type=str, dest="mail_to", help="Destinataire du mail")
parser.add_argument("-r", "--repository", action="store", type=str, dest="repo", help="Path du dépôt")
parser.add_argument("-u", "--untracked", action="store_true", dest="untracked", help="Affiche aussi les fichiers non trackés")
parser.add_argument("-d", "--debug", action="store_true", dest="debug", help="Affiche le mail au lieu de l'envoyer")
parser.set_defaults(**DEFAULTS)
args = parser.parse_args()
# Si un path de dépôt est fourni, on s'y cd
if args.repo:
os.chdir(args.repo)
out = get_status_silentfail()
out = get_status_silentfail(args.untracked)
if out:
send(out, args.mail_from, args.mail_to, args.debug)