Skip to content

Add show dates and other changes #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions bin/git-bc-show-eligible
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@

from __future__ import unicode_literals

import subprocess
import argparse
import datetime
import pygit2
import sys
import re
import subprocess
import sys

def find_toplevel():
try:
Expand Down Expand Up @@ -58,7 +59,10 @@ def main():
parser.add_argument('target_branch', metavar='TARGET_BRANCH', help='Name for the target branch',
default='HEAD', nargs='?')
parser.add_argument('--since', metavar='COMMIT', help='Start checking since specified commit')
parser.add_argument('--show-dates', action='store_true', help='Show dates in %Y-%m-%d %H:%M:%S')

parser.add_argument('--all', action='store_true', help='Show commits from all users')
parser.add_argument('--always-colors', action='store_true', help='Always force colored output')

top = find_toplevel()

Expand Down Expand Up @@ -96,14 +100,22 @@ def main():
author_format_str = ' | %s <%s>'
commit_format_str = '%s %s%s'

if sys.stdout.isatty():
if sys.stdout.isatty() or args.always_colors:
author_format_str = ' \033[31m| %s <%s>\033[0m'
commit_format_str = '\033[33m%s\033[0m %s%s'

seen = ''
groups = []
current_group = []
for commit in find_unpicked(repo, from_commit, to_commit, since_commit, args.all):
formatted_date = ''
if args.show_dates:
timestamp = commit.commit_time # commit timestamp
offset = commit.commit_time_offset # timezone offset in minutes
commit_date = datetime.datetime.utcfromtimestamp(timestamp)
commit_date += datetime.timedelta(minutes=offset)
formatted_date = commit_date.strftime('%Y-%m-%d %H:%M:%S') + ' - '

author_info = ''
if args.all:
author_info = author_format_str % (commit.author.name, commit.author.email)
Expand All @@ -112,7 +124,7 @@ def main():
indent = commit_msg in seen
seen += commit.message

commit_string = (commit_format_str % (str(commit.id), commit_msg, author_info))
commit_string = formatted_date + (commit_format_str % (str(commit.id), commit_msg, author_info))

if indent:
current_group.append(commit_string)
Expand Down