Update changelog for recent commits
[stgit.git] / stgit / commands / clone.py
blobbb232267e674b254f2b8c01d598140fc02b9efe6
1 import os
3 from stgit.commands.common import (
4 CmdException,
5 DirectoryAnywhere,
6 DirectoryHasRepository,
8 from stgit.lib.git import clone
9 from stgit.lib.stack import Stack
11 __copyright__ = """
12 Copyright (C) 2009, Catalin Marinas <catalin.marinas@gmail.com>
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License version 2 as
16 published by the Free Software Foundation.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, see http://www.gnu.org/licenses/.
25 """
27 help = 'Make a local clone of a remote repository'
28 kind = 'repo'
29 usage = ['<repository> <dir>']
30 description = """
31 Clone a git repository into the local directory <dir> (using
32 linkstg:clone[]) and initialise the local branch "master".
34 This operation is for example suitable to start working using the
35 "tracking branch" workflow (see link:stg[1]). Other means to setup
36 an StGit stack are linkstg:init[] and the '--create' and '--clone'
37 commands of linkstg:branch[].
39 The target directory <dir> will be created by this command, and must
40 not already exist."""
42 args = ['repo', 'dir']
43 options = []
45 directory = DirectoryAnywhere()
48 def func(parser, options, args):
49 """Clone the repository into the local dir and initialise the stack."""
50 if len(args) != 2:
51 parser.error('incorrect number of arguments')
53 repository = args[0]
54 local_dir = args[1]
56 if os.path.exists(local_dir):
57 raise CmdException('"%s" exists. Remove it first' % local_dir)
59 clone(repository, local_dir)
60 os.chdir(local_dir)
61 directory = DirectoryHasRepository()
62 directory.setup()
63 Stack.initialise(directory.repository)