2014-05-30 21:24:35 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
# git-branch-check: Compare your local git branches with the remote.
|
|
|
|
#
|
|
|
|
# Usage: git-branch-check [remote]
|
|
|
|
#
|
|
|
|
# Default remote name is "origin", provide [remote] to change that.
|
|
|
|
#
|
|
|
|
# --Kirsle
|
|
|
|
# https://www.kirsle.net/
|
|
|
|
|
2017-04-27 17:58:56 +00:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2014-05-30 21:24:35 +00:00
|
|
|
import sys
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
remote = "origin"
|
|
|
|
if len(sys.argv) >= 2:
|
|
|
|
remote = sys.argv[1]
|
|
|
|
|
|
|
|
local_branch = set()
|
|
|
|
remote_branch = set()
|
|
|
|
|
2017-04-27 17:58:56 +00:00
|
|
|
subprocess.call(["git", "remote", "update", remote, "--prune"])
|
|
|
|
|
|
|
|
data = subprocess.check_output(["git", "branch", "-a"]).decode()
|
2014-05-30 21:24:35 +00:00
|
|
|
for line in data.split("\n"):
|
|
|
|
# Remove the currently active branch indicator and extra spaces.
|
|
|
|
line = line.strip("*").strip()
|
|
|
|
if not len(line): continue
|
|
|
|
|
|
|
|
# Remote branch?
|
|
|
|
if line.startswith("remotes/{}/".format(remote)):
|
|
|
|
line = line.replace("remotes/{}/".format(remote), "")
|
|
|
|
remote_branch.add(line)
|
|
|
|
elif line.startswith("remotes/"):
|
|
|
|
# A different remote?
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
local_branch.add(line)
|
|
|
|
|
|
|
|
# Show comparisons.
|
2017-04-27 17:58:56 +00:00
|
|
|
print("Local branches that are not on the remote:")
|
2014-05-30 21:24:35 +00:00
|
|
|
for branch in sorted(local_branch):
|
|
|
|
if not branch in remote_branch:
|
2017-04-27 17:58:56 +00:00
|
|
|
print("*", branch)
|
2014-05-30 21:24:35 +00:00
|
|
|
|
|
|
|
# vim:expandtab
|