Skip to content

Commit

Permalink
Make install work under venvs
Browse files Browse the repository at this point in the history
  • Loading branch information
frostming committed Sep 19, 2019
1 parent 0a266a8 commit c8ac1d4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
18 changes: 9 additions & 9 deletions legit/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from .settings import legit_settings
from .utils import (
black, format_help, git_version, order_manually, output_aliases,
status_log, verbose_echo
status_log, verbose_echo, program_path
)

CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
Expand Down Expand Up @@ -265,18 +265,18 @@ def do_install(ctx, verbose, fake):
"""Installs legit git aliases."""
click.echo('The following git aliases will be installed:\n')
aliases = cli.list_commands(ctx)
if git_version() >= (2, 23, 0):
click.echo(
'As git 2.23.0 introduces a new command "git switch", alias "switch"'
' will be skipped.\nUse "legit switch" instead.'
)
aliases.remove('switch')
output_aliases(aliases)
git_v = git_version()

program = program_path()
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
cmd = '!{} {}'.format(program, alias)
system_command = 'git config --global --replace-all alias.{0} "{1}"'.format(alias, cmd)
verbose_echo(system_command, verbose, fake)
if not fake:
Expand Down
8 changes: 8 additions & 0 deletions legit/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import click
from clint.textui import colored, columns
import crayons
import os
import sys

from .settings import legit_settings

Expand Down Expand Up @@ -124,3 +126,9 @@ def git_version():

g = Git()
return g.version_info


def program_path():
result = os.path.abspath(sys.argv[0])
result = result.replace(os.sep, '/').replace(' ', '\\ ')
return result

0 comments on commit c8ac1d4

Please sign in to comment.