<commit_before>#!/usr/bin/env python
# -*- coding: UTF-8 -*-

# change those symbols to whatever you prefer
symbols = {'ahead of': '↑', 'behind': '↓', 'staged':'♦', 'changed':'‣', 'untracked':'…', 'clean':'⚡', 'unmerged':'≠', 'sha1':':'}

from subprocess import Popen, PIPE

output,error = Popen(['git','status'], stdout=PIPE, stderr=PIPE).communicate()

if error:
	import sys
	sys.exit(0)

status = ''

def execute(*command):
	out, err = Popen(*command, stdout=PIPE, stderr=PIPE).communicate()
	if not err:
		nb = len(out.splitlines())
	else:
		nb = '?'
	return nb

nb = execute(['git','diff','--staged','--name-only','--diff-filter=ACDMRT'])
if nb:
	status += '%s%s' % (symbols['staged'], nb)
nb = execute(['git','diff', '--staged','--name-only', '--diff-filter=U'])
if nb:
	status += '%s%s' % (symbols['unmerged'], nb)
nb = execute(['git','diff','--name-only', '--diff-filter=ACDMRT'])
if nb:
	status += '%s%s' % (symbols['changed'], nb)
nb = len(Popen(['git','ls-files','--others','--exclude-standard'],stdout=PIPE).communicate()[0].splitlines())
## 		status += "%s" % (symbols['untracked']*(nb//3 + 1), )
if nb:
	status += symbols['untracked']
if status == '':
	status = symbols['clean']

remote = ''

branch = Popen(['git', 'symbolic-ref', 'HEAD'], stdout=PIPE).communicate()[0][11:-1]
if not branch: # not on any branch
	branch = symbols['sha1']+ Popen(['git','rev-parse','--short','HEAD'], stdout=PIPE).communicate()[0][:-1]
else:
	remote_branch = Popen(['git', 'branch', '-r'], stdout=PIPE).communicate()[0].splitlines()[-1][2:]
## 	remote_branch = 'master'
	behind = len(Popen(['git', 'rev-list', 'HEAD..%s' % remote_branch],stdout=PIPE).communicate()[0].splitlines())
	ahead = len(Popen(['git', 'rev-list', '%s..HEAD' % remote_branch],stdout=PIPE).communicate()[0].splitlines())
	if behind:
		remote += '%s%s' % (symbols['behind'], behind)
	if ahead:
		remote += '%s%s' % (symbols['ahead of'], ahead)
	
print '\n'.join([branch,remote,status])
<commit_msg>some hocus pocus to determine which branch to track<commit_after>#!/usr/bin/env python
# -*- coding: UTF-8 -*-

# change those symbols to whatever you prefer
symbols = {'ahead of': '↑', 'behind': '↓', 'staged':'♦', 'changed':'‣', 'untracked':'…', 'clean':'⚡', 'unmerged':'≠', 'sha1':':'}

from subprocess import Popen, PIPE

output,error = Popen(['git','status'], stdout=PIPE, stderr=PIPE).communicate()

if error:
	import sys
	sys.exit(0)

status = ''

def execute(*command):
	out, err = Popen(*command, stdout=PIPE, stderr=PIPE).communicate()
	if not err:
		nb = len(out.splitlines())
	else:
		nb = '?'
	return nb

nb = execute(['git','diff','--staged','--name-only','--diff-filter=ACDMRT'])
if nb:
	status += '%s%s' % (symbols['staged'], nb)
nb = execute(['git','diff', '--staged','--name-only', '--diff-filter=U'])
if nb:
	status += '%s%s' % (symbols['unmerged'], nb)
nb = execute(['git','diff','--name-only', '--diff-filter=ACDMRT'])
if nb:
	status += '%s%s' % (symbols['changed'], nb)
nb = len(Popen(['git','ls-files','--others','--exclude-standard'],stdout=PIPE).communicate()[0].splitlines())
## 		status += "%s" % (symbols['untracked']*(nb//3 + 1), )
if nb:
	status += symbols['untracked']
if status == '':
	status = symbols['clean']

remote = ''

branch = Popen(['git', 'symbolic-ref', 'HEAD'], stdout=PIPE).communicate()[0][11:-1]
if not branch: # not on any branch
	branch = symbols['sha1']+ Popen(['git','rev-parse','--short','HEAD'], stdout=PIPE).communicate()[0][:-1]
else:
	if branch == 'master':
		remote_branch = Popen(['git', 'branch', '-r'], stdout=PIPE).communicate()[0].splitlines()[-1][2:]
	else:
		remote_branch = 'master'
	behind = len(Popen(['git', 'rev-list', 'HEAD..%s' % remote_branch],stdout=PIPE).communicate()[0].splitlines())
	ahead = len(Popen(['git', 'rev-list', '%s..HEAD' % remote_branch],stdout=PIPE).communicate()[0].splitlines())
	if behind:
		remote += '%s%s' % (symbols['behind'], behind)
	if ahead:
		remote += '%s%s' % (symbols['ahead of'], ahead)
	
print '\n'.join([branch,remote,status])

{'fraction_non_alphanumeric': 0.2645, 'fraction_numerical': 0.009, 'mean_word_length': 5.505691056910569, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7605826', 'n_tokens_mistral': 1543, 'n_tokens_neox': 1502, 'n_words': 302}