Skip to content

Commit

Permalink
Don't install alias 'switch' on git 2.23.0 or later
Browse files Browse the repository at this point in the history
Fix #256
  • Loading branch information
frostming committed Sep 19, 2019
1 parent e23d707 commit 36a02fc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ History
1.0.2
+++++

* Don't install ``switch`` on git>=2.23.0.
* Update requirements
* Fix Windows executable release
* Improve tests
Expand Down
15 changes: 12 additions & 3 deletions legit/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@
import os

import click
import crayons
from clint import resources
from clint.textui import columns
import crayons

from .core import __version__
from .scm import SCMRepo
from .settings import legit_settings
from .utils import black, format_help, order_manually, output_aliases, status_log, verbose_echo

from .utils import (
black, format_help, git_version, order_manually, output_aliases,
status_log, verbose_echo
)

CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
pass_scm = click.make_pass_decorator(SCMRepo)
Expand Down Expand Up @@ -264,9 +266,16 @@ def do_install(ctx, verbose, fake):
click.echo('The following git aliases will be installed:\n')
aliases = cli.list_commands(ctx)
output_aliases(aliases)
git_v = git_version()

if click.confirm('\n{}Install aliases above?'.format('FAKE ' if fake else ''), default=fake):
for alias in aliases:
if alias == 'switch' and git_v >= (2, 23, 0):
click.echo(
'As git 2.23.0 introduces a new command "git switch", alias "switch"'
' will be skipped.\nUse shortname "git sw" or "legit switch" instead.'
)
continue
cmd = '!legit ' + alias
system_command = 'git config --global --replace-all alias.{0} "{1}"'.format(alias, cmd)
verbose_echo(system_command, verbose, fake)
Expand Down
8 changes: 8 additions & 0 deletions legit/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,11 @@ def black(s, **kwargs):
return crayons.black(s, **kwargs)
else:
return s.encode('utf-8')


def git_version():
"""Return the git version tuple (major, minor, patch)"""
from git import Git

g = Git()
return g.version_info

0 comments on commit 36a02fc

Please sign in to comment.