Skip to content

Commit

Permalink
Git rel -a
Browse files Browse the repository at this point in the history
  • Loading branch information
tkrajina committed Aug 3, 2018
1 parent e284ab5 commit 0c5227f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ Another example:
1d3b97c Tomo Krajina Preparations for marker handler, 3 weeks ago
9546769 Tomo Krajina Removed all subscription stuff, 3 months ago

By default, `git-rel` shows no more than 30 commits (if there are more some will be omitted). You can show the list of all commits with:

$ git relation -a branch-1 branch-2

## Git old-branches

Old-branches can detect old/unused branches.
Expand Down
14 changes: 8 additions & 6 deletions git-relation
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ parser.add_argument('branch_2', metavar='branch_2', type=str, nargs='?', default
help='the other commit/tag/branch (default HEAD)')
parser.add_argument('-b', '--brief', action='store_true',
default=False, help='brief output')
parser.add_argument('-a', '--all', action='store_true',
default=False, help='show all commits')

args = parser.parse_args()

Expand All @@ -46,7 +48,7 @@ def get_git_sha1(branch_name):
return sha1.strip()


def print_log(commit_1, commit_2):
def print_log(commit_1, commit_2, all_commits=False):
success, log = mod_gitutils.execute_git(
'log %s..%s --format=%%x20%%x20%%x20%%h%%x20%%Cgreen%%an%%Creset%%x20\"%%Cred%%s%%Creset\",%%x20%%ar' % (commit_1, commit_2),
output=False)
Expand All @@ -60,7 +62,7 @@ def print_log(commit_1, commit_2):
print
print '%s commits from \033[1;34m%s\033[0m to \033[1;34m%s\033[0m:' % (len(lines), commit_1, commit_2)

if len(lines) < 30:
if all_commits or len(lines) < 30:
print result
return

Expand Down Expand Up @@ -95,14 +97,14 @@ elif merge_base == branch_1_sha1 and merge_base == branch_2_sha1:
elif merge_base == branch_1_sha1:
print '\033[1;34m%s\033[0m is \033[1;31mBEHIND\033[0m \033[1;34m%s\033[0m by %d commits' % (branch_1, branch_2, distance_to_commit(branch_1, branch_2))
if not args.brief:
print_log(branch_1, branch_2)
print_log(branch_1, branch_2, args.all)
elif merge_base == branch_2_sha1:
print '\033[1;34m%s\033[0m is \033[1;31mAHEAD\033[0m of \033[1;34m%s\033[0m by %d commits' % (branch_1, branch_2, distance_to_commit(branch_2, branch_1))
if not args.brief:
print_log(branch_2, branch_1)
print_log(branch_2, branch_1, args.all)
else:
print '\033[1;34m%s\033[0m and \033[1;34m%s\033[0m \033[1;31mDIVERGED\033[0m by respectively %d and %d commits' % (branch_1, branch_2, distance_to_commit(merge_base, branch_1), distance_to_commit(merge_base, branch_2))
if not args.brief:
print 'common point is \033[1;34m%s\033[0m'%(merge_base)
print_log(merge_base, branch_1)
print_log(merge_base, branch_2)
print_log(merge_base, branch_1, args.all)
print_log(merge_base, branch_2, args.all)

0 comments on commit 0c5227f

Please sign in to comment.