Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
spderosso committed Jun 15, 2016
2 parents f5637d7 + eaa55e6 commit 123ac24
Show file tree
Hide file tree
Showing 10 changed files with 388 additions and 56 deletions.
6 changes: 3 additions & 3 deletions gitless/cli/gl.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from gitless import core

from . import (
gl_track, gl_untrack, gl_status, gl_diff, gl_commit, gl_branch,
gl_track, gl_untrack, gl_status, gl_diff, gl_commit, gl_branch, gl_tag,
gl_checkout, gl_merge, gl_resolve, gl_fuse, gl_remote, gl_publish,
gl_switch, gl_init, gl_history)
from . import pprint
Expand All @@ -29,7 +29,7 @@
INTERNAL_ERROR = 3
NOT_IN_GL_REPO = 4

VERSION = '0.8.2'
VERSION = '0.8.3'
URL = 'http://gitless.com'


Expand All @@ -55,7 +55,7 @@ def main():
subparsers.required = True

sub_cmds = [
gl_track, gl_untrack, gl_status, gl_diff, gl_commit, gl_branch,
gl_track, gl_untrack, gl_status, gl_diff, gl_commit, gl_branch, gl_tag,
gl_checkout, gl_merge, gl_resolve, gl_fuse, gl_remote, gl_publish,
gl_switch, gl_init, gl_history]
for sub_cmd in sub_cmds:
Expand Down
17 changes: 3 additions & 14 deletions gitless/cli/gl_branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@

from __future__ import unicode_literals

try:
from StringIO import StringIO
except ImportError:
from io import StringIO

from clint.textui import colored

from gitless import core
Expand Down Expand Up @@ -93,14 +88,14 @@ def _do_list(repo, list_remote, v=False):
pprint.item(
'{0} {1} {2}'.format(current_str, color(b.branch_name), upstream_str))
if v:
pprint.item(' ➜ head is {0}'.format(_ci_str(b.head)))
pprint.item(' ➜ head is {0}'.format(pprint.commit_str(b.head)))

if list_remote:
for r in repo.remotes:
for b in (r.lookup_branch(n) for n in r.listall_branches()):
pprint.item(' {0}'.format(colored.yellow(str(b))))
if v:
pprint.item(' ➜ head is {0}'.format(_ci_str(b.head)))
pprint.item(' ➜ head is {0}'.format(pprint.commit_str(b.head)))


def _do_create(create_b, dp, repo):
Expand Down Expand Up @@ -190,11 +185,5 @@ def _do_set_head(commit_id, repo):
curr_b = repo.current_branch
curr_b.head = commit.id
pprint.ok(
'Head of current branch {0} is now {1}'.format(curr_b, _ci_str(commit)))
'Head of current branch {0} is now {1}'.format(curr_b, pprint.commit_str(commit)))
return True


def _ci_str(ci):
ci_str = StringIO()
pprint.commit(ci, compact=True, stream=ci_str.write)
return ci_str.getvalue().strip()
35 changes: 33 additions & 2 deletions gitless/cli/gl_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

from __future__ import unicode_literals

import subprocess
from sh import git

from gitless import core

from . import commit_dialog
Expand All @@ -24,6 +27,10 @@ def parser(subparsers, repo):
'flags'))
commit_parser.add_argument(
'-m', '--message', help='Commit message', dest='m')
commit_parser.add_argument(
'-p', '--partial',
help='Interactively select segments of files to commit', dest='p',
action='store_true')
helpers.oei_flags(commit_parser, repo)
commit_parser.set_defaults(func=main)

Expand All @@ -36,13 +43,19 @@ def main(args, repo):
pprint.err_exp('use gl track f if you want to track changes to file f')
return False

curr_b = repo.current_branch
partials = None
if args.p:
partials = _do_partial_selection(commit_files, curr_b)

msg = args.m if args.m else commit_dialog.show(commit_files, repo)
if not msg.strip():
if partials:
git.reset('HEAD', partials)
raise ValueError('Missing commit message')

curr_b = repo.current_branch
_auto_track(commit_files, curr_b)
ci = curr_b.create_commit(commit_files, msg)
ci = curr_b.create_commit(commit_files, msg, partials=partials)
pprint.ok('Commit succeeded')

pprint.blank()
Expand All @@ -56,6 +69,24 @@ def main(args, repo):
return True


def _do_partial_selection(files, curr_b):
partials = []
for fp in files:
f_st = curr_b.status_file(fp)
if not f_st.exists_at_head:
pprint.warn('Can\'t select segments for new file {0}'.format(fp))
continue
if not f_st.exists_in_wd:
pprint.warn('Can\'t select segments for deleted file {0}'.format(fp))
continue

subprocess.call(['git', 'add', '-p', fp])
# TODO: check that at least one hunk was staged
partials.append(fp)

return partials


def _auto_track(files, curr_b):
"""Tracks those untracked files in the list."""
for fp in files:
Expand Down
21 changes: 13 additions & 8 deletions gitless/cli/gl_fuse.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def parser(subparsers, repo):
fuse_parser.add_argument(
'-ip', '--insertion-point', nargs='?',
help=(
'the commit where to put the divergent changes, dp for '
'the divergent changes will be inserted after the commit given, dp for '
'divergent point is the default'), metavar='commit_id')
fuse_parser.add_argument(
'-a', '--abort', help='abort the fuse in progress', action='store_true')
Expand All @@ -55,11 +55,21 @@ def main(args, repo):
return True

src_branch = helpers.get_branch_or_use_upstream(args.src, 'src', repo)
dp = repo.merge_base(current_b, src_branch)

mb = repo.merge_base(current_b, src_branch)
if mb == src_branch.target: # the current branch is ahead or both branches are equal
pprint.err('No commits to fuse')
return False

if (not args.insertion_point or args.insertion_point == 'dp' or
args.insertion_point == 'divergent-point'):
insertion_point = mb
else:
insertion_point = repo.revparse_single(args.insertion_point).id

def valid_input(inp):
walker = src_branch.history()
walker.hide(dp)
walker.hide(insertion_point)
divergent_ids = frozenset(ci.id for ci in walker)

errors_found = False
Expand All @@ -81,11 +91,6 @@ def valid_input(inp):
if not valid_input(exclude):
return False

if (not args.insertion_point or args.insertion_point == 'dp' or
args.insertion_point == 'divergent-point'):
insertion_point = dp
else:
insertion_point = repo.revparse_single(args.insertion_point).id

try:
current_b.fuse(
Expand Down
128 changes: 128 additions & 0 deletions gitless/cli/gl_tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# -*- coding: utf-8 -*-
# Gitless - a version control system built on top of Git.
# Licensed under GNU GPL v2.

"""gl tag - List, create, edit or delete tags."""


from __future__ import unicode_literals

from gitless import core

from . import helpers, pprint


def parser(subparsers, _):
"""Adds the tag parser to the given subparsers object."""
desc = 'list, create, or delete tags'
tag_parser = subparsers.add_parser(
'tag', help=desc, description=desc.capitalize())
tag_parser.add_argument(
'-r', '--remote',
help='list remote tags in addition to local tags',
action='store_true')

tag_parser.add_argument(
'-c', '--create', nargs='+', help='create tag(s)', dest='create_t',
metavar='tag')
tag_parser.add_argument(
'-ci', '--commit',
help='the commit to tag (only relevant if a new '
'tag is created; defaults to the HEAD commit)', default='HEAD',
dest='ci')
tag_parser.add_argument(
'-d', '--delete', nargs='+', help='delete tag(s)', dest='delete_t',
metavar='tag')

tag_parser.set_defaults(func=main)


def main(args, repo):
ret = True
if args.create_t:
ret = _do_create(args.create_t, args.ci, repo)
elif args.delete_t:
ret = _do_delete(args.delete_t, repo)
else:
_do_list(repo, args.remote)

return ret


def _do_list(repo, list_remote):
pprint.msg('List of tags:')
pprint.exp('do gl tag -c t to create tag t')
pprint.exp('do gl tag -d t to delete tag t')
pprint.blank()

no_tags = True
for t in (repo.lookup_tag(n) for n in repo.listall_tags()):
pprint.item('{0} ➜ tags {1}'.format(t, pprint.commit_str(t.commit)))
no_tags = False

if list_remote:
for r in repo.remotes:
for t in (r.lookup_tag(n) for n in r.listall_tags()):
pprint.item('{0} ➜ tags {1}'.format(t, pprint.commit_str(t.commit)))
no_tags = False

if no_tags:
pprint.item('There are no tags to list')


def _do_create(create_t, dp, repo):
errors_found = False

try:
target = repo.revparse_single(dp)
except KeyError:
raise ValueError('Invalid commit {0}'.format(dp))

for t_name in create_t:
r = repo
remote_str = ''
if '/' in t_name: # might want to create a remote tag
maybe_remote, maybe_remote_tag = t_name.split('/', 1)
if maybe_remote in repo.remotes:
r = repo.remotes[maybe_remote]
t_name = maybe_remote_tag
conf_msg = 'Tag {0} will be created in remote repository {1}'.format(
t_name, maybe_remote)
if not pprint.conf_dialog(conf_msg):
pprint.msg(
'Aborted: creation of tag {0} in remote repository {1}'.format(
t_name, maybe_remote))
continue
remote_str = ' in remote repository {0}'.format(maybe_remote)
try:
r.create_tag(t_name, target)
pprint.ok('Created new tag {0}{1}'.format(t_name, remote_str))
except ValueError as e:
pprint.err(e)
errors_found = True

return not errors_found


def _do_delete(delete_t, repo):
errors_found = False

for t_name in delete_t:
try:
t = helpers.get_tag(t_name, repo)

tag_str = 'Tag {0} will be removed'.format(t.tag_name)
remote_str = ''
if isinstance(t, core.RemoteTag):
remote_str = 'from remote repository {0}'.format(t.remote_name)
if not pprint.conf_dialog('{0} {1}'.format(tag_str, remote_str)):
pprint.msg('Aborted: removal of tag {0}'.format(t))
continue

t.delete()
pprint.ok('Tag {0} removed successfully'.format(t))
except ValueError as e:
pprint.err(e)
errors_found = True

return not errors_found
36 changes: 23 additions & 13 deletions gitless/cli/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,35 @@


def get_branch(branch_name, repo):
b = repo.lookup_branch(branch_name)
if not b:
if '/' not in branch_name:
raise ValueError('Branch "{0}" doesn\'t exist'.format(branch_name))
return _get_ref("branch", branch_name, repo)

# It might be a remote branch
remote, remote_branch = branch_name.split('/', 1)

def get_tag(tag_name, repo):
return _get_ref("tag", tag_name, repo)


def _get_ref(ref_type, ref_name, repo):
ref_type_cap = ref_type.capitalize()
r = getattr(repo, "lookup_" + ref_type)(ref_name)
if not r:
if '/' not in ref_name:
raise ValueError(
'{0} "{1}" doesn\'t exist'.format(ref_type_cap, ref_name))

# It might be a remote ref
remote, remote_ref = ref_name.split('/', 1)
try:
r = repo.remotes[remote]
remote_repo = repo.remotes[remote]
except KeyError:
raise ValueError(
'Remote "{0}" doesn\'t exist, and there is no local '
'branch "{1}"'.format(remote, branch_name))
'{1} "{2}"'.format(remote, ref_type_cap, ref_name))

b = r.lookup_branch(remote_branch)
if not b:
raise ValueError('Branch "{0}" doesn\'t exist in remote "{1}"'.format(
remote_branch, remote))
return b
r = getattr(remote_repo, "lookup_" + ref_type)(remote_ref)
if not r:
raise ValueError('{0} "{1}" doesn\'t exist in remote "{2}"'.format(
ref_type_cap, remote_ref, remote))
return r


def get_branch_or_use_upstream(branch_name, arg, repo):
Expand Down
11 changes: 11 additions & 0 deletions gitless/cli/pprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

from __future__ import unicode_literals

try:
from StringIO import StringIO
except ImportError:
from io import StringIO

from datetime import datetime, tzinfo, timedelta
from locale import getpreferredencoding
import re
Expand Down Expand Up @@ -124,6 +129,12 @@ def get_user_input(text='> '):
return input(text)


def commit_str(ci):
ci_str = StringIO()
commit(ci, compact=True, stream=ci_str.write)
return ci_str.getvalue().strip()


def commit(ci, compact=False, stream=sys.stdout.write):
merge_commit = len(ci.parent_ids) > 1
color = colored.magenta if merge_commit else colored.yellow
Expand Down

0 comments on commit 123ac24

Please sign in to comment.