Move endpoints into separate submodule. Add shorthand for pushing/pulling refs.

This commit is contained in:
jan 2020-12-20 18:24:21 -08:00
parent 8fb7eca501
commit ab95369801
5 changed files with 83 additions and 24 deletions

View File

@ -2,11 +2,14 @@
Git snapshotting tool
"""
from .lethe import (
main, snap, snap_ref, snap_tree, find_merge_base, deref_symref,
snap, snap_ref, snap_tree, find_merge_base, deref_symref,
update_ref, commit_tree, get_tree, get_commit, get_obj,
shorten_hash, get_root, get_latest_commit,
push_ref, fetch_ref,
)
from .endpoints import main
from .VERSION import __version__
__author__ = 'Jan Petykeiwicz'

View File

@ -1,4 +1,4 @@
from .lethe import main
from .endpoints import main
if __name__ == '__main__':
main()

47
lethe/endpoints.py Normal file
View File

@ -0,0 +1,47 @@
import argparse
from .lethe import snap, push_ref, fetch_ref
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument('--parent', '-p', action='append', default=['HEAD'])
parser.add_argument('--target', '-t', action='append')
parser.add_argument('--message', '-m')
parser.add_argument('--repo', '-r')
args = parser.parse_args()
print(snap(parent_refs=args.parent,
target_refs=args.target,
message=args.message,
cwd=args.repo))
return 0
def push() -> int:
parser = argparse.ArgumentParser()
parser.add_argument('--remote', '-s', default='origin')
parser.add_argument('--target', '-t', default='refs/lethe/HEAD')
parser.add_argument('--repo', '-r')
args = parser.parse_args()
print(push_ref(remote=args.remote,
target_ref=args.target,
cwd=args.repo))
return 0
def fetch() -> int:
parser = argparse.ArgumentParser()
parser.add_argument('--remote', '-s', default='origin')
parser.add_argument('--target', '-t', default='refs/lethe/HEAD')
parser.add_argument('--repo', '-r')
args = parser.parse_args()
print(fetch_ref(remote=args.remote,
remote_ref=args.target,
cwd=args.repo))
return 0

View File

@ -110,6 +110,34 @@ def update_ref(target_ref: str,
return result_ref
def push_ref(remote: str = 'origin',
target_ref: str = 'refs/lethe/HEAD',
remote_ref: Optional[str] = None,
cwd: Optional[str] = None,
) -> str:
"""
Push `target_ref` to `remote` as `remote_ref`.
By default, `remote_ref` will be the same as `target_ref`.
"""
if remote_ref is None:
remote_ref = target_ref
return _run(['git', 'push', remote, target_ref + ':' + remote_ref], cwd=cwd)
def fetch_ref(remote: str = 'origin',
remote_ref: str = 'refs/lethe/HEAD',
target_ref: Optional[str] = None,
cwd: Optional[str] = None,
) -> str:
"""
Fetch `remote_ref` from `remote` as `target_ref`.
By default, `target_ref` will be the same as `remote_ref`.
"""
if target_ref is None:
target_ref = remote_ref
return _run(['git', 'fetch', remote, remote_ref + ':' + target_ref], cwd=cwd)
def deref_symref(ref: str, cwd: Optional[str] = None) -> str:
"""
Dereference a symbolic ref
@ -214,24 +242,3 @@ def snap(parent_refs: Optional[List[str]] = None,
commit = snap_ref(parent_refs, target_refs, message=message, cwd=cwd)
return commit
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument('--parent', '-p', action='append', default=['HEAD'])
parser.add_argument('--target', '-t', action='append')
parser.add_argument('--message', '-m')
parser.add_argument('--repo', '-r')
args = parser.parse_args()
print(snap(parent_refs=args.parent,
target_refs=args.target,
message=args.message,
cwd=args.repo))
return 0
if __name__ == '__main__':
main()

View File

@ -23,7 +23,9 @@ setup(name='lethe',
},
entry_points={
'console_scripts': [
'lethe=lethe:main',
'lethe=lethe:endpoints.main',
'lethe-push=lethe:endpoints.push',
'lethe-fetch=lethe:endpoints.fetch',
],
},
install_requires=[