Merge lp:~mattyw/codetree/git-depth into lp:codetree

Proposed by Matthew Williams
Status: Merged
Merged at revision: 78
Proposed branch: lp:~mattyw/codetree/git-depth
Merge into: lp:codetree
Diff against target: 72 lines (+39/-2)
2 files modified
codetree/handlers/git.py (+6/-2)
tests/test_git_handler.py (+33/-0)
To merge this branch: bzr merge lp:~mattyw/codetree/git-depth
Reviewer Review Type Date Requested Status
Tom Haddon Approve
Review via email: mp+312469@code.launchpad.net

Commit message

Add support for specifying depth=n option when cloning from git repos. This allows shallow copies to be done which is especially useful in the case of cloning fat charms

Description of the change

Add support for specifying depth=n option when cloning from git repos. This allows shallow copies to be done which is especially useful in the case of cloning fat charms

To post a comment you must log in.
Revision history for this message
Tom Haddon (mthaddon) wrote :

Looks good, thanks, but I think we should check the depth option is an integer.

review: Needs Fixing
lp:~mattyw/codetree/git-depth updated
80. By mattyw <email address hidden>

handlers/git: Support depth option as int or stringed in

Revision history for this message
Tom Haddon (mthaddon) wrote :

Great, thanks.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'codetree/handlers/git.py'
2--- codetree/handlers/git.py 2016-11-28 23:53:35 +0000
3+++ codetree/handlers/git.py 2016-12-06 10:23:27 +0000
4@@ -65,10 +65,14 @@
5 def get(self, dest, options):
6 ref = options.get('revno')
7
8+ clone_command = ['git', 'clone', self.source, dest]
9+ if options.get("depth"):
10+ depth = int(options.get("depth"))
11+ clone_command.extend(["--depth", str(depth)])
12 if os.path.exists(dest):
13 if options.get("overwrite"):
14 shutil.rmtree(dest)
15- if not log_failure(['git', 'clone', self.source, dest],
16+ if not log_failure(clone_command,
17 "Cloning repository at {} from {}".format(dest, self.source)):
18 return False
19 else:
20@@ -77,7 +81,7 @@
21 if ref is None: # default to master for the checkout of any updated repo
22 ref = 'master'
23 else:
24- if not log_failure(['git', 'clone', self.source, dest],
25+ if not log_failure(clone_command,
26 "Cloning repository at {} from {}".format(dest, self.source)):
27 return False
28
29
30=== modified file 'tests/test_git_handler.py'
31--- tests/test_git_handler.py 2016-05-10 20:46:25 +0000
32+++ tests/test_git_handler.py 2016-12-06 10:23:27 +0000
33@@ -98,6 +98,39 @@
34 finally:
35 shutil.rmtree(d)
36
37+ def test_get_revision_depth_1(self):
38+ gh = GitSourceHandler("git://localhost/.git")
39+ d = mkdtemp('', 'git-handler')
40+ wd = os.path.join(d, 'test')
41+ try:
42+ gh.get(wd, {'revno': self._revision, 'depth': 1})
43+ rev_count = subprocess.check_output(gh._git_cmd(wd, 'rev-list', '--count', '--all'))
44+ self.assertEqual('1', rev_count.strip())
45+ finally:
46+ shutil.rmtree(d)
47+
48+ def test_get_revision_depth_1_str(self):
49+ gh = GitSourceHandler("git://localhost/.git")
50+ d = mkdtemp('', 'git-handler')
51+ wd = os.path.join(d, 'test')
52+ try:
53+ gh.get(wd, {'revno': self._revision, 'depth': "1"})
54+ rev_count = subprocess.check_output(gh._git_cmd(wd, 'rev-list', '--count', '--all'))
55+ self.assertEqual('1', rev_count.strip())
56+ finally:
57+ shutil.rmtree(d)
58+
59+ def test_get_revision_depth_is_int(self):
60+ gh = GitSourceHandler("git://localhost/.git")
61+ d = mkdtemp('', 'git-handler')
62+ wd = os.path.join(d, 'test')
63+ try:
64+ with self.assertRaises(ValueError):
65+ gh.get(wd, {'revno': self._revision, 'depth': "invalid"})
66+ finally:
67+ shutil.rmtree(d)
68+
69+
70 def test_directory_exists(self):
71 gh = GitSourceHandler("git://localhost/.git")
72 d = mkdtemp('', 'git-handler')

Subscribers

People subscribed via source and target branches