This command is based on the existing git-clone-script.
Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
- tag (snapshot) command
- log command (it should also show the log per single patch)
-- clone command
- improved import command to import patches from a different branch in
the same tree
- tutorial, man page
--- /dev/null
+__copyright__ = """
+Copyright (C) 2005, Catalin Marinas <catalin.marinas@gmail.com>
+
+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.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+"""
+
+import sys, os
+from optparse import OptionParser, make_option
+
+from stgit.commands.common import *
+from stgit.utils import *
+from stgit import stack, git
+
+
+help = 'pull the changes from the remote repository'
+usage = """%prog [options] <repository> <dir>
+
+Clone a GIT <repository> into the local <dir> and initialise the
+patch stack."""
+
+options = []
+
+
+def func(parser, options, args):
+ """Clone the <repository> into the local <dir> and initialises the
+ stack
+ """
+ if len(args) != 2:
+ parser.error('incorrect number of arguments')
+
+ repository = args[0]
+ local_dir = args[1]
+
+ if os.path.exists(local_dir):
+ raise CmdException, '"%s" exists. Remove it first' % local_dir
+
+ print 'Cloning "%s" into "%s"...' % (repository, local_dir)
+
+ git.clone(repository, local_dir)
+ os.chdir(local_dir)
+ git.checkout(tree_id = 'HEAD')
+
+ crt_series.init()
+
+ print 'done'
return str.rstrip()
-def checkout(files = [], force = False):
+def checkout(files = [], tree_id = None, force = False):
"""Check out the given or all files
"""
- git_flags = 'git-checkout-cache -q -u'
+ if tree_id and __run('git-read-tree -m', [tree_id]) != 0:
+ raise GitException, 'Failed git-read-tree -m %s' % tree_id
+
+ checkout_cmd = 'git-checkout-cache -q -u'
if force:
- git_flags += ' -f'
+ checkout_cmd += ' -f'
if len(files) == 0:
- git_flags += ' -a'
+ checkout_cmd += ' -a'
else:
- git_flags += ' --'
+ checkout_cmd += ' --'
- if __run(git_flags, files) != 0:
+ if __run(checkout_cmd, files) != 0:
raise GitException, 'Failed git-checkout-cache'
def switch(tree_id):
to_delete = filter(lambda x: x[0] in ['N', 'A'],
__tree_status(tree_id = tree_id))
- if __run('git-read-tree -m', [tree_id]) != 0:
- raise GitException, 'Failed git-read-tree -m %s' % tree_id
-
- checkout(force = True)
+ checkout(tree_id = tree_id, force = True)
__set_head(tree_id)
# checkout doesn't remove files
raise GitException, 'Patch does not apply cleanly'
else:
_input('git-apply --index', sys.stdin)
+
+def clone(repository, local_dir):
+ """Clone a remote repository. At the moment, just use the
+ 'git clone' script
+ """
+ if __run('git clone', [repository, local_dir]) != 0:
+ raise GitException, 'Failed "git clone %s %s"' \
+ % (repository, local_dir)
import stgit.commands.delete
import stgit.commands.diff
import stgit.commands.clean
+import stgit.commands.clone
import stgit.commands.export
import stgit.commands.files
import stgit.commands.imprt
'delete': stgit.commands.delete,
'diff': stgit.commands.diff,
'clean': stgit.commands.clean,
+ 'clone': stgit.commands.clone,
'export': stgit.commands.export,
'files': stgit.commands.files,
'import': stgit.commands.imprt,
option_list = command.options)
options, args = parser.parse_args()
try:
- # the lines below are a simple way to avoid an exception when
+ # 'clone' doesn't expect an already initialised GIT tree
+ if cmd == 'clone':
+ stgit.commands.common.crt_series = stack.Series('master')
+ else:
+ stgit.commands.common.crt_series = stack.Series()
+ # the line below is a simple way to avoid an exception when
# stgit is run outside an initialised tree
- stgit.commands.common.crt_series = stack.Series()
setattr(command, 'crt_series', stgit.commands.common.crt_series)
command.func(parser, options, args)