Move all UI-facing string generation to main gitcheckup.
This commit is contained in:
parent
eed52e5247
commit
88b3baafb8
1 changed files with 32 additions and 33 deletions
|
@ -2,6 +2,7 @@ import argparse
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
import types
|
||||||
|
|
||||||
from voussoirkit import winwhich
|
from voussoirkit import winwhich
|
||||||
|
|
||||||
|
@ -35,17 +36,8 @@ def checkup_committed():
|
||||||
if {'D'}.intersection(status):
|
if {'D'}.intersection(status):
|
||||||
deleted += 1
|
deleted += 1
|
||||||
|
|
||||||
if (added, modified, deleted) == (0, 0, 0):
|
committed = (added, modified, deleted) == (0, 0, 0)
|
||||||
committed = True
|
details = types.SimpleNamespace(added=added, deleted=deleted, modified=modified)
|
||||||
details = ''
|
|
||||||
else:
|
|
||||||
committed = False
|
|
||||||
details = []
|
|
||||||
if added: details.append(f'+{added}')
|
|
||||||
if deleted: details.append(f'-{deleted}')
|
|
||||||
if modified: details.append(f'~{modified}')
|
|
||||||
details = ', '.join(details)
|
|
||||||
details = f'({details})'
|
|
||||||
|
|
||||||
return (committed, details)
|
return (committed, details)
|
||||||
|
|
||||||
|
@ -65,16 +57,11 @@ def checkup_pushed():
|
||||||
to_push = len(git_commits_between(merge_base, my_head))
|
to_push = len(git_commits_between(merge_base, my_head))
|
||||||
to_pull = len(git_commits_between(merge_base, remote_head))
|
to_pull = len(git_commits_between(merge_base, remote_head))
|
||||||
|
|
||||||
if (to_push, to_pull) == (0, 0):
|
pushed = (to_push, to_pull) == (0, 0)
|
||||||
pushed = True
|
details = types.SimpleNamespace(
|
||||||
details = ''
|
to_push=to_push,
|
||||||
else:
|
to_pull=to_pull,
|
||||||
pushed = False
|
)
|
||||||
details = []
|
|
||||||
if to_push: details.append(f'↑{to_push}')
|
|
||||||
if to_pull: details.append(f'↓{to_pull}')
|
|
||||||
details = ', '.join(details)
|
|
||||||
details = f'({details})'
|
|
||||||
|
|
||||||
return (pushed, details)
|
return (pushed, details)
|
||||||
|
|
||||||
|
@ -94,12 +81,12 @@ def checkup(directory, do_fetch=False):
|
||||||
git_fetch()
|
git_fetch()
|
||||||
(committed, commit_details) = checkup_committed()
|
(committed, commit_details) = checkup_committed()
|
||||||
(pushed, push_details) = checkup_pushed()
|
(pushed, push_details) = checkup_pushed()
|
||||||
return {
|
return types.SimpleNamespace(
|
||||||
'committed': committed,
|
committed=committed,
|
||||||
'commit_details': commit_details,
|
commit_details=commit_details,
|
||||||
'pushed': pushed,
|
pushed=pushed,
|
||||||
'push_details': push_details,
|
push_details=push_details,
|
||||||
}
|
)
|
||||||
|
|
||||||
def read_directories_file():
|
def read_directories_file():
|
||||||
directories_file = os.path.join(os.path.dirname(__file__), 'gitcheckup.txt')
|
directories_file = os.path.join(os.path.dirname(__file__), 'gitcheckup.txt')
|
||||||
|
@ -122,14 +109,26 @@ def gitcheckup(do_fetch=False):
|
||||||
|
|
||||||
for directory in directories:
|
for directory in directories:
|
||||||
result = checkup(directory, do_fetch=do_fetch)
|
result = checkup(directory, do_fetch=do_fetch)
|
||||||
committed = 'C' if result['committed'] else ' '
|
committed = 'C' if result.committed else ' '
|
||||||
pushed = 'P' if result['pushed'] else ' '
|
pushed = 'P' if result.pushed else ' '
|
||||||
|
|
||||||
details = []
|
details = []
|
||||||
if result['commit_details']:
|
|
||||||
details.append(result['commit_details'])
|
commit_details = []
|
||||||
if result['push_details']:
|
if result.commit_details.added: commit_details.append(f'+{result.commit_details.added}')
|
||||||
details.append(result['push_details'])
|
if result.commit_details.deleted: commit_details.append(f'-{result.commit_details.deleted}')
|
||||||
|
if result.commit_details.modified: commit_details.append(f'~{result.commit_details.modified}')
|
||||||
|
commit_details = ', '.join(commit_details)
|
||||||
|
commit_details = f'({commit_details})' if commit_details else ''
|
||||||
|
details.append(commit_details)
|
||||||
|
|
||||||
|
push_details = []
|
||||||
|
if result.push_details.to_push: push_details.append(f'↑{result.push_details.to_push}')
|
||||||
|
if result.push_details.to_pull: push_details.append(f'↓{result.push_details.to_pull}')
|
||||||
|
push_details = ', '.join(push_details)
|
||||||
|
push_details = f'({push_details})' if push_details else ''
|
||||||
|
details.append(push_details)
|
||||||
|
|
||||||
details = ' '.join(details)
|
details = ' '.join(details)
|
||||||
details = (' ' + details).rstrip()
|
details = (' ' + details).rstrip()
|
||||||
print(f'[{committed}][{pushed}] {directory}{details}')
|
print(f'[{committed}][{pushed}] {directory}{details}')
|
||||||
|
|
Loading…
Reference in a new issue