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