Write to a stack log when stack is modified
[stgit] / stgit / commands / clone.py
CommitLineData
1008fbce
CM
1__copyright__ = """
2Copyright (C) 2005, Catalin Marinas <catalin.marinas@gmail.com>
3
4This program is free software; you can redistribute it and/or modify
5it under the terms of the GNU General Public License version 2 as
6published by the Free Software Foundation.
7
8This program is distributed in the hope that it will be useful,
9but WITHOUT ANY WARRANTY; without even the implied warranty of
10MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11GNU General Public License for more details.
12
13You should have received a copy of the GNU General Public License
14along with this program; if not, write to the Free Software
15Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16"""
17
18import sys, os
1008fbce
CM
19from stgit.commands.common import *
20from stgit.utils import *
21from stgit import stack, git
22
575bbdae 23help = 'Make a local clone of a remote repository'
33ff9cdd 24kind = 'repo'
575bbdae
KH
25usage = ['<repository> <dir>']
26description = """
27Clone a git repository into the local directory <dir> (using
a1e0467d 28stglink:clone[]) and initialise the local branch "master".
1008fbce 29
575bbdae 30This operation is for example suitable to start working using the
a1e0467d 31"tracking branch" workflow (see link:stg[1]). Other means to setup
575bbdae
KH
32an StGit stack are stglink:init[] and the '--create' and '--clone'
33commands of stglink:branch[].
1008fbce 34
575bbdae
KH
35The target directory <dir> will be created by this command, and must
36not already exist."""
1008fbce
CM
37
38options = []
39
117ed129 40directory = DirectoryAnywhere(needs_current_series = False, log = False)
1008fbce
CM
41
42def func(parser, options, args):
43 """Clone the <repository> into the local <dir> and initialises the
44 stack
45 """
46 if len(args) != 2:
47 parser.error('incorrect number of arguments')
48
49 repository = args[0]
50 local_dir = args[1]
51
52 if os.path.exists(local_dir):
53 raise CmdException, '"%s" exists. Remove it first' % local_dir
54
55 print 'Cloning "%s" into "%s"...' % (repository, local_dir)
56
57 git.clone(repository, local_dir)
58 os.chdir(local_dir)
59 git.checkout(tree_id = 'HEAD')
60
608961c2
YD
61 # be sure to forget any cached value for .git, since we're going
62 # to work on a brand new repository
63 basedir.clear_cache()
98290387 64 stack.Series().init()
1008fbce
CM
65
66 print 'done'