/usr/bin/git-cola is in git-cola 1.9.3-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 | #! /usr/bin/python
# -*- python-mode -*-
"""git-cola: The highly caffeinated Git GUI
"""
__copyright__ = """
Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013
David Aguilar <davvid@gmail.com> and contributors
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
"""
import os
import sys
import subprocess
from argparse import ArgumentParser
from os.path import abspath
from os.path import dirname
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
prefix = dirname(dirname(realpath(abspath(__file__))))
# 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()
from cola import core
from cola import cmds
from cola.app import add_common_arguments
from cola.app import application_init
from cola.app import application_start
def main():
# we're using argparse with subparser, but argparse
# does not allow us to assign a default subparser
# when none has been specified. We fake it by injecting
# 'cola' into the command-line so that parse_args()
# routes them to the 'cola' parser by default.
if (len(sys.argv) < 2 or
sys.argv[1].startswith('-') and
sys.argv[1] not in ('-h', '--help')):
sys.argv.insert(1, 'cola')
args = parse_args()
return args.func(args)
def parse_args():
parser = ArgumentParser()
subparser = parser.add_subparsers(title='valid commands')
add_cola_command(subparser)
add_archive_command(subparser)
add_branch_command(subparser)
add_browse_command(subparser)
add_config_command(subparser)
add_dag_command(subparser)
add_diff_command(subparser)
add_fetch_command(subparser)
add_grep_command(subparser)
add_merge_command(subparser)
add_pull_command(subparser)
add_push_command(subparser)
add_rebase_command(subparser)
add_remote_command(subparser)
add_search_command(subparser)
add_stash_command(subparser)
add_tag_command(subparser)
add_version_command(subparser)
return parser.parse_args()
def add_command(parent, name, description, func):
parser = parent.add_parser(name, help=description)
parser.set_defaults(func=func)
add_common_arguments(parser)
return parser
def add_cola_command(subparser):
parser = add_command(subparser, 'cola', 'start git-cola', cmd_cola)
parser.add_argument('--amend', default=False, action='store_true',
help='start in amend mode')
def add_archive_command(parent):
parser = add_command(parent, 'archive', 'save an archive', cmd_archive)
parser.add_argument('ref', metavar='<ref>', nargs='?', default=None,
help='SHA-1 to archive')
def add_branch_command(subparser):
add_command(subparser, 'branch', 'create a branch', cmd_branch)
def add_browse_command(subparser):
add_command(subparser, 'browse', 'browse repository', cmd_browse)
add_command(subparser, 'classic', 'browse repository', cmd_browse)
def add_config_command(subparser):
add_command(subparser, 'config', 'edit configuration', cmd_config)
def add_dag_command(subparser):
parser = add_command(subparser, 'dag', 'start git-dag', cmd_dag)
parser.add_argument('-c', '--count', metavar='<count>',
type=int, default=1000,
help='number of commits to display')
parser.add_argument('args', nargs='*', metavar='<args>',
help='git log arguments')
def add_diff_command(subparser):
parser = add_command(subparser, 'diff', 'view diffs', cmd_diff)
parser.add_argument('args', nargs='*', metavar='<args>',
help='git diff arguments')
def add_fetch_command(subparser):
add_command(subparser, 'fetch', 'fetch remotes', cmd_fetch)
def add_grep_command(subparser):
parser = add_command(subparser, 'grep', 'grep source', cmd_grep)
parser.add_argument('args', nargs='*', metavar='<args>',
help='git grep arguments')
def add_merge_command(subparser):
add_command(subparser, 'merge', 'merge branches', cmd_merge)
def add_pull_command(subparser):
parser = add_command(subparser, 'pull', 'pull remote branches', cmd_pull)
parser.add_argument('--rebase', default=False, action='store_true',
help='rebase local branch when pulling')
def add_push_command(subparser):
add_command(subparser, 'push', 'push remote branches', cmd_push)
def add_rebase_command(subparser):
parser = add_command(subparser, 'rebase', 'interactive rebase', cmd_rebase)
parser.add_argument('branch', metavar='<branch>',
help='New upstream branch')
def add_remote_command(subparser):
add_command(subparser, 'remote', 'edit remotes', cmd_remote)
def add_search_command(subparser):
add_command(subparser, 'search', 'search commits', cmd_search)
def add_stash_command(subparser):
add_command(subparser, 'stash', 'stash and unstash changes', cmd_stash)
def add_tag_command(subparser):
parser = add_command(subparser, 'tag', 'create tags', cmd_tag)
parser.add_argument('name', metavar='<name>', nargs='?', default=None,
help='tag name')
parser.add_argument('ref', metavar='<ref>', nargs='?', default=None,
help='SHA-1 to tag')
parser.add_argument('-s', '--sign', default=False, action='store_true',
help='annotated and GPG-signed tag')
def add_version_command(subparser):
parser = add_command(subparser, 'version', 'print the version', cmd_version)
parser.add_argument('--brief', action='store_true', default=False,
help='print the version number only')
# entry points
def cmd_cola(args):
context = application_init(args)
from cola.widgets.main import MainView
view = MainView(context.model)
if args.amend:
cmds.do(cmds.AmendMode, True)
return application_start(context, view)
def cmd_archive(args):
context = application_init(args, update=True)
if args.ref is None:
args.ref = context.model.currentbranch
from cola.widgets.archive import GitArchiveDialog
view = GitArchiveDialog(args.ref)
return application_start(context, view)
def cmd_branch(args):
context = application_init(args, update=True)
from cola.widgets.createbranch import create_new_branch
view = create_new_branch()
return application_start(context, view)
def cmd_browse(args):
context = application_init(args)
from cola.widgets.browse import worktree_browser
view = worktree_browser(update=False)
return application_start(context, view)
def cmd_config(args):
context = application_init(args)
from cola.widgets.prefs import preferences
view = preferences()
return application_start(context, view)
def cmd_dag(args):
context = application_init(args)
from cola.widgets.dag import git_dag
view = git_dag(context.model, args=args)
return application_start(context, view)
def cmd_diff(args):
context = application_init(args)
from cola.difftool import diff_expression
expr = subprocess.list2cmdline(map(core.decode, args.args))
view = diff_expression(None, expr, create_widget=True)
return application_start(context, view)
def cmd_fetch(args):
# TODO: the calls to update_status() can be done asynchronously
# by hooking into the message_updated notification.
context = application_init(args)
from cola.widgets import remote
context.model.update_status()
view = remote.fetch()
return application_start(context, view)
def cmd_grep(args):
context = application_init(args)
from cola.widgets import grep
text = subprocess.list2cmdline(map(core.decode, args.args))
view = grep.run_grep(text=text, parent=None)
return application_start(context, view)
def cmd_merge(args):
context = application_init(args, update=True)
from cola.widgets.merge import MergeView
view = MergeView(context.model, parent=None)
return application_start(context, view)
def cmd_version(args):
from cola import version
version.print_version(brief=args.brief)
return 0
def cmd_pull(args):
context = application_init(args, update=True)
from cola.widgets import remote
view = remote.pull()
if args.rebase:
view.set_rebase(True)
return application_start(context, view)
def cmd_push(args):
context = application_init(args, update=True)
from cola.widgets import remote
view = remote.push()
return application_start(context, view)
def cmd_rebase(args):
status, out, err = cmds.do(cmds.Rebase, args.branch)
if out:
core.stdout(out)
if err:
core.stderr(err)
return status
def cmd_remote(args):
context = application_init(args)
from cola.widgets import editremotes
view = editremotes.edit()
return application_start(context, view)
def cmd_search(args):
context = application_init(args)
from cola.widgets.search import search
view = search()
return application_start(context, view)
def cmd_stash(args):
context = application_init(args)
from cola.widgets.stash import stash
view = stash()
return application_start(context, view)
def cmd_tag(args):
context = application_init(args)
from cola.widgets.createtag import create_tag
view = create_tag(name=args.name, ref=args.ref, sign=args.sign)
return application_start(context, view)
if __name__ == '__main__':
sys.exit(main())
|