|
@@ -1,17 +1,33 @@
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import string
|
|
import string
|
|
import subprocess
|
|
import subprocess
|
|
|
|
+import sys
|
|
|
|
|
|
class Branch:
|
|
class Branch:
|
|
MERGED=1
|
|
MERGED=1
|
|
@@ -21,7 +37,7 @@ class Branch:
|
|
last_commit = ""
|
|
last_commit = ""
|
|
|
|
|
|
|
|
|
|
-def branch_list_get():
|
|
+def branch_list_get(verbose):
|
|
txt_list = subprocess.check_output(["git", "branch", "-r"])
|
|
txt_list = subprocess.check_output(["git", "branch", "-r"])
|
|
|
|
|
|
txt_list = txt_list.split(b"\n")
|
|
txt_list = txt_list.split(b"\n")
|
|
@@ -42,7 +58,9 @@ def branch_list_get():
|
|
branch_info.name = branch_info.name.decode("utf-8")
|
|
branch_info.name = branch_info.name.decode("utf-8")
|
|
|
|
|
|
|
|
|
|
- print ("Checking branch %s" % branch_info.name)
|
|
+ if verbose:
|
|
|
|
+ print("Checking branch %s" % branch_info.name)
|
|
|
|
+
|
|
cmd = ["git", "diff", "master..." + branch_info.name ]
|
|
cmd = ["git", "diff", "master..." + branch_info.name ]
|
|
diff = subprocess.check_output(cmd)
|
|
diff = subprocess.check_output(cmd)
|
|
if (len(diff) == 0):
|
|
if (len(diff) == 0):
|
|
@@ -66,40 +84,88 @@ def branch_list_get():
|
|
|
|
|
|
return (out)
|
|
return (out)
|
|
|
|
|
|
-def branch_print(branches, print_merged, print_notmerged, print_stats):
|
|
+def branch_print(branches, csv, print_merged, print_notmerged, print_stats):
|
|
merged = 0
|
|
merged = 0
|
|
notmerged = 0
|
|
notmerged = 0
|
|
|
|
+ merged_str = ""
|
|
|
|
+ notmerged_str = ""
|
|
for branch in branches:
|
|
for branch in branches:
|
|
if (branch.status==Branch.MERGED):
|
|
if (branch.status==Branch.MERGED):
|
|
merged = merged + 1
|
|
merged = merged + 1
|
|
if (not print_merged):
|
|
if (not print_merged):
|
|
continue
|
|
continue
|
|
- print("%s,merged,%s" % (branch.name, branch.last_commit) )
|
|
+ if (csv):
|
|
|
|
+ print("%s,merged,%s" % (branch.name, branch.last_commit) )
|
|
|
|
+ else:
|
|
|
|
+ merged_str = merged_str + " " + branch.name
|
|
else:
|
|
else:
|
|
|
|
|
|
notmerged = notmerged + 1
|
|
notmerged = notmerged + 1
|
|
if (not print_notmerged):
|
|
if (not print_notmerged):
|
|
continue
|
|
continue
|
|
- print("%s,notmerged,%s" % (branch.name, branch.last_commit) )
|
|
+ if (csv):
|
|
|
|
+ print("%s,notmerged,%s" % (branch.name, branch.last_commit) )
|
|
|
|
+ else:
|
|
|
|
+ notmerged_str = notmerged_str + " " + branch.name
|
|
|
|
+
|
|
|
|
+ if (not csv):
|
|
|
|
+ if (print_merged):
|
|
|
|
+ print("Merged branches : %s" % (merged_str))
|
|
|
|
+ if (print_notmerged):
|
|
|
|
+ print("NOT merged branches: %s" % (notmerged_str))
|
|
|
|
|
|
if (print_stats):
|
|
if (print_stats):
|
|
print("#----------");
|
|
print("#----------");
|
|
print("#Merged : %d" % merged)
|
|
print("#Merged : %d" % merged)
|
|
print("#Not merged: %d" % notmerged)
|
|
print("#Not merged: %d" % notmerged)
|
|
|
|
|
|
|
|
+def show_help():
|
|
|
|
+ print("This script prints out merged and/or unmerged branches of a GIT tree.")
|
|
|
|
+ print("Supported command-line options:")
|
|
|
|
+ print("")
|
|
|
|
+ print("--csv produce CSV (coma separated value) output")
|
|
|
|
+ print("--unmerged lists umerged branches")
|
|
|
|
+ print("--skip-merged do not print merged branches (that are listed by default)")
|
|
|
|
+ print("--stats prints out statistics")
|
|
|
|
+ print("--help prints out this help")
|
|
|
|
+
|
|
def main():
|
|
def main():
|
|
usage = """%prog
|
|
usage = """%prog
|
|
Lists all obsolete (fully merged into master) branches.
|
|
Lists all obsolete (fully merged into master) branches.
|
|
"""
|
|
"""
|
|
|
|
|
|
- print("branch name,status,date,last commit(mail),last commit(name)")
|
|
+ csv = False;
|
|
|
|
+ merged = True;
|
|
|
|
+ unmerged = False;
|
|
|
|
+ stats = False;
|
|
|
|
+
|
|
|
|
+ for x in sys.argv[1:]:
|
|
|
|
+ if x == "--csv":
|
|
|
|
+ csv = True;
|
|
|
|
+ elif x == "--unmerged":
|
|
|
|
+ unmerged = True;
|
|
|
|
+ elif x == "--skip-merged":
|
|
|
|
+ merged = False;
|
|
|
|
+ elif x == "--stats":
|
|
|
|
+ stats = True;
|
|
|
|
+ elif x == "--help":
|
|
|
|
+ show_help()
|
|
|
|
+ return
|
|
|
|
+ else:
|
|
|
|
+ print("Invalid parameter: %s" % x)
|
|
|
|
+ print("")
|
|
|
|
+ show_help()
|
|
|
|
+ return
|
|
|
|
+
|
|
|
|
+ if csv:
|
|
|
|
+ print("branch name,status,date,last commit(mail),last commit(name)")
|
|
|
|
|
|
- branch_list = branch_list_get()
|
|
+ branch_list = branch_list_get(not csv)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- branch_print(branch_list, True, False, True)
|
|
+ branch_print(branch_list, csv, merged, unmerged, stats)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
if __name__ == '__main__':
|
|
main()
|
|
main()
|