Skip to content

Commit

Permalink
Merge pull request #1 from git-cola/master
Browse files Browse the repository at this point in the history
Merge upstream changes
  • Loading branch information
Vdragon committed Aug 11, 2014
2 parents 90b70d2 + ee97664 commit 7f6d82c
Show file tree
Hide file tree
Showing 76 changed files with 19,847 additions and 14,348 deletions.
12 changes: 9 additions & 3 deletions bin/git-cola
Expand Up @@ -26,23 +26,29 @@ import sys
import subprocess
from os.path import abspath
from os.path import dirname
from os.path import join
from os.path import realpath


def setup_environment():
"""Provides access to the cola modules"""
# Try to detect where it is run from and set prefix and the search path.
# It is assumed that the user installed Cola using the --prefix= option
python2 = sys.version_info[0] == 2
prefix = dirname(dirname(realpath(abspath(__file__))))
if python2:
cola_mod = join(prefix, str('cola'), str('__init__.py'))
install_lib = join(prefix, str('share'), str('git-cola'), str('lib'))
else:
# Look for modules in the source or install trees
cola_mod = os.path.join(prefix, 'cola', '__init__.py')
install_lib = os.path.join(prefix, 'share', 'git-cola', 'lib')

# Look for modules in the source or install trees
cola_mod = os.path.join(prefix, 'cola', '__init__.py')
if os.path.exists(cola_mod):
# Source tree
sys.path.insert(1, prefix)
else:
# Install tree
install_lib = os.path.join(prefix, 'share', 'git-cola', 'lib')
sys.path.insert(1, install_lib)
setup_environment()

Expand Down
13 changes: 10 additions & 3 deletions bin/git-dag
Expand Up @@ -25,22 +25,29 @@ import sys
from argparse import ArgumentParser
from os.path import abspath
from os.path import dirname
from os.path import join
from os.path import realpath


def setup_environment():
"""Provides access to the cola modules"""
# Try to detect where it is run from and set prefix and the search path.
# It is assumed that the user installed Cola using the --prefix= option
python2 = sys.version_info[0] == 2
prefix = dirname(dirname(realpath(abspath(__file__))))
if python2:
cola_mod = join(prefix, str('cola'), str('__init__.py'))
install_lib = join(prefix, str('share'), str('git-cola'), str('lib'))
else:
# Look for modules in the source or install trees
cola_mod = os.path.join(prefix, 'cola', '__init__.py')
install_lib = os.path.join(prefix, 'share', 'git-cola', 'lib')

# Look for modules in the source or install trees
cola_mod = os.path.join(prefix, 'cola', '__init__.py')
if os.path.exists(cola_mod):
# Source tree
sys.path.insert(1, prefix)
else:
# Install tree
install_lib = os.path.join(prefix, 'share', 'git-cola', 'lib')
sys.path.insert(1, install_lib)
setup_environment()

Expand Down
2 changes: 1 addition & 1 deletion cola/_version.py
@@ -1,2 +1,2 @@
# The current git-cola version
VERSION = '2.0.3'
VERSION = '2.0.5'
10 changes: 6 additions & 4 deletions cola/app.py
Expand Up @@ -50,6 +50,7 @@
from cola import version
from cola.compat import ustr
from cola.decorators import memoize
from cola.i18n import N_
from cola.interaction import Interaction
from cola.models import main
from cola.widgets import cfgactions
Expand Down Expand Up @@ -203,7 +204,7 @@ def commitData(self, session_mgr):
skey = ustr(session_mgr.sessionKey())
session_id = '%s_%s' % (sid, skey)
session = Session(session_id,
repo=os.getcwdu(), git_path=self.git_path)
repo=core.getcwd(), git_path=self.git_path)
self.view.save_state(settings=session)


Expand All @@ -228,8 +229,9 @@ def process_args(args):
repo = repo[len('file:'):]
repo = core.realpath(repo)
if not core.isdir(repo):
sys.stderr.write("fatal: '%s' is not a directory. "
'Consider supplying -r <path>.\n' % repo)
errmsg = N_('fatal: "%s" is not a directory. '
'Please specify a correct --repo <path>.') % repo
core.stderr(errmsg)
sys.exit(-1)

# We do everything relative to the repo root
Expand Down Expand Up @@ -305,7 +307,7 @@ def add_common_arguments(parser):
help='print version number')

# Specifies a git repository to open
parser.add_argument('-r', '--repo', metavar='<repo>', default=os.getcwd(),
parser.add_argument('-r', '--repo', metavar='<repo>', default=core.getcwd(),
help='open the specified git repository')

# Specifies that we should prompt for a repository at startup
Expand Down
106 changes: 71 additions & 35 deletions cola/cmds.py
Expand Up @@ -13,7 +13,6 @@
from cola import utils
from cola import difftool
from cola import resources
from cola.compat import ustr
from cola.diffparse import DiffParser
from cola.git import STDOUT
from cola.i18n import N_
Expand Down Expand Up @@ -50,10 +49,12 @@ def name():
return 'Unknown'

def do(self):
raise NotImplementedError('%s.do() is unimplemented' % self.__class__.__name__)
raise NotImplementedError('%s.do() is unimplemented'
% self.__class__.__name__)

def undo(self):
raise NotImplementedError('%s.undo() is unimplemented' % self.__class__.__name__)
raise NotImplementedError('%s.undo() is unimplemented'
% self.__class__.__name__)


class Command(BaseCommand):
Expand Down Expand Up @@ -148,11 +149,9 @@ def undo(self):

class ApplyDiffSelection(Command):

def __init__(self, staged, selected, offset, selection_text,
apply_to_worktree):
def __init__(self, staged, offset, selection_text, apply_to_worktree):
Command.__init__(self)
self.staged = staged
self.selected = selected
self.offset = offset
self.selection_text = selection_text
self.apply_to_worktree = apply_to_worktree
Expand All @@ -164,8 +163,7 @@ def do(self):
cached=self.staged,
reverse=self.apply_to_worktree)
status, out, err = \
parser.process_diff_selection(self.selected,
self.offset,
parser.process_diff_selection(self.offset,
self.selection_text,
apply_to_worktree=self.apply_to_worktree)
Interaction.log_status(status, out, err)
Expand Down Expand Up @@ -331,9 +329,16 @@ def __init__(self, amend, msg):
self.new_commitmsg = ''

def do(self):
# Create the commit message file
msg = self.strip_comments(self.msg)
tmpfile = utils.tmp_filename('commit-message')
status, out, err = self.model.commit_with_msg(self.msg, tmpfile,
amend=self.amend)
core.write(tmpfile, msg)

# Run 'git commit'
status, out, err = self.model.git.commit(F=tmpfile, v=True,
amend=self.amend)
core.unlink(tmpfile)

if status == 0:
ResetMode.do(self)
self.model.set_commitmsg(self.new_commitmsg)
Expand All @@ -344,13 +349,24 @@ def do(self):

return status, out, err

@staticmethod
def strip_comments(msg):
# Strip off comments
message_lines = [line for line in msg.split('\n')
if not line.startswith('#')]
msg = '\n'.join(message_lines)
if not msg.endswith('\n'):
msg += '\n'

return msg


class Ignore(Command):
"""Add files to .gitignore"""

def __init__(self, filenames):
Command.__init__(self)
self.filenames = filenames
self.filenames = list(filenames)

def do(self):
if not self.filenames:
Expand All @@ -368,6 +384,8 @@ def do(self):
class Delete(Command):
"""Delete files."""

SHORTCUT = 'Ctrl+Backspace'

def __init__(self, filenames):
Command.__init__(self)
self.filenames = filenames
Expand Down Expand Up @@ -503,7 +521,7 @@ class Edit(Command):

@staticmethod
def name():
return N_('Edit')
return N_('Launch Editor')

def __init__(self, filenames, line_number=None):
Command.__init__(self)
Expand Down Expand Up @@ -539,18 +557,19 @@ def do(self):
try:
core.fork(utils.shell_split(editor) + opts)
except Exception as e:
message = (N_('Cannot exec "%s": please configure your editor') %
editor)
Interaction.critical(N_('Error Editing File'), message, ustr(e))
message = (N_('Cannot exec "%s": please configure your editor')
% editor)
details = core.decode(e.strerror)
Interaction.critical(N_('Error Editing File'), message, details)


class FormatPatch(Command):
"""Output a patch series given all revisions and a selected subset."""

def __init__(self, to_export, revs):
Command.__init__(self)
self.to_export = to_export
self.revs = revs
self.to_export = list(to_export)
self.revs = list(revs)

def do(self):
status, out, err = gitcmds.format_patchsets(self.to_export, self.revs)
Expand All @@ -575,15 +594,18 @@ def do(self):
if utils.is_win32():
core.fork(['git', 'mergetool', '--no-prompt', '--'] + paths)
else:
core.fork(['xterm', '-e',
'git', 'mergetool', '--no-prompt', '--'] + paths)
cmd = _config.terminal()
argv = utils.shell_split(cmd)
argv.extend(['git', 'mergetool', '--no-prompt', '--'])
argv.extend(paths)
core.fork(argv)
else:
difftool.run()


class LaunchTerminal(BaseCommand):

SHORTCUT = 'Ctrl+t'
SHORTCUT = 'Ctrl+T'

@staticmethod
def name():
Expand All @@ -594,9 +616,9 @@ def __init__(self, path):
self.path = path

def do(self):
cmd = _config.get('cola.terminal', 'xterm -e $SHELL')
cmd = os.path.expandvars(cmd)
cmd = _config.terminal()
argv = utils.shell_split(cmd)
argv.append(os.getenv('SHELL', '/bin/sh'))
core.fork(argv, cwd=self.path)


Expand Down Expand Up @@ -679,20 +701,23 @@ def __init__(self, sha1):


class Merge(Command):
def __init__(self, revision, no_commit, squash):
def __init__(self, revision, no_commit, squash, noff):
Command.__init__(self)
self.revision = revision
self.no_ff = noff
self.no_commit = no_commit
self.squash = squash

def do(self):
squash = self.squash
revision = self.revision
no_ff = self.no_ff
no_commit = self.no_commit
msg = gitcmds.merge_message(revision)

status, out, err = self.model.git.merge('-m', msg,
revision,
no_ff=no_ff,
no_commit=no_commit,
squash=squash)

Expand Down Expand Up @@ -782,18 +807,25 @@ def __init__(self, url, new_directory, spawn=True):
self.new_directory = new_directory
self.spawn = spawn

self.ok = False
self.error_message = ''
self.error_details = ''

def do(self):
status, out, err = self.model.git.clone(self.url, self.new_directory)
if status != 0:
Interaction.information(
N_('Error: could not clone "%s"') % self.url,
self.ok = status == 0

if self.ok:
if self.spawn:
core.fork([sys.executable, sys.argv[0],
'--repo', self.new_directory])
else:
self.error_message = N_('Error: could not clone "%s"') % self.url
self.error_details = (
(N_('git clone returned exit code %s') % status) +
((out+err) and ('\n\n' + out + err) or ''))
return False
if self.spawn:
core.fork([sys.executable, sys.argv[0],
'--repo', self.new_directory])
return True
((out+err) and ('\n\n' + out + err) or ''))

return self


class GitXBaseContext(object):
Expand Down Expand Up @@ -961,7 +993,10 @@ def do(self):
Interaction.log(N_('Running command: %s') % title)
cmd = ['sh', '-c', cmd]

if opts.get('noconsole'):
if opts.get('background'):
core.fork(cmd)
status, out, err = (0, '', '')
elif opts.get('noconsole'):
status, out, err = core.run_command(cmd)
else:
status, out, err = Interaction.run_command(title, cmd)
Expand All @@ -970,7 +1005,7 @@ def do(self):
out and (N_('Output: %s') % out) or '',
err and (N_('Errors: %s') % err) or '')

if not opts.get('norescan'):
if not opts.get('background') and not opts.get('norescan'):
self.model.update_status()
return status

Expand Down Expand Up @@ -1140,6 +1175,7 @@ def do(self):
Interaction.log_status(status, log_msg, err)
if status == 0:
self.model.update_status()
return (status, output, err)


class Unstage(Command):
Expand Down Expand Up @@ -1238,7 +1274,7 @@ def __init__(self, paths):
Command.__init__(self)
browser = utils.shell_split(prefs.history_browser())
if paths:
self.argv = browser + paths
self.argv = browser + list(paths)
else:
self.argv = browser

Expand Down
5 changes: 5 additions & 0 deletions cola/compat.py
Expand Up @@ -2,7 +2,9 @@
import sys


PY2 = sys.version_info[0] == 2
PY3 = sys.version_info[0] >= 3
WIN32 = sys.platform == 'win32' or sys.platform == 'cygwin'

try:
ustr = unicode
Expand All @@ -23,12 +25,15 @@
except ImportError:
import urllib


def setenv(key, value):
"""Compatibility wrapper for setting environment variables
Why? win32 requires putenv(). UNIX only requires os.environ.
"""
if not PY3 and type(value) is ustr:
value = value.encode('utf-8', 'replace')
os.environ[key] = value
os.putenv(key, value)

Expand Down

0 comments on commit 7f6d82c

Please sign in to comment.