Merge lp:~lazypower/charm-helpers/git-fetch-update into lp:charm-helpers

Proposed by Charles Butler
Status: Needs review
Proposed branch: lp:~lazypower/charm-helpers/git-fetch-update
Merge into: lp:charm-helpers
Diff against target: 31 lines (+10/-0)
1 file modified
charmhelpers/fetch/giturl.py (+10/-0)
To merge this branch: bzr merge lp:~lazypower/charm-helpers/git-fetch-update
Reviewer Review Type Date Requested Status
charmers Pending
Review via email: mp+270135@code.launchpad.net

Description of the change

This alters the behavior of the git fetcher by adding a small loop to attempt updating of a git repository if the path exists on disk prior to attempting a clone.

The existing behavior is to raise a UnhandledRepositoryUrl exception when the path exists, which is a bit confusing to consumers of install_remote with git VCS urls - which seems to be a one shot fetcher. Run once, and guard against subsequent runs.

If this would fundamentally change the behavior of install_remote, i do not +1 this merge, but wanted to start the conversation around this small patch to see if we can't update charm-helpers to be a little more VCS friendly for cheap operations like an update.

To post a comment you must log in.

Unmerged revisions

441. By Charles Butler

Adds a small logic loop to attempt an update of an existing directory if the
directory exists, and the git handler has assumed control from install_remote.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmhelpers/fetch/giturl.py'
2--- charmhelpers/fetch/giturl.py 2015-07-09 19:56:05 +0000
3+++ charmhelpers/fetch/giturl.py 2015-09-04 03:48:06 +0000
4@@ -27,10 +27,13 @@
5
6 try:
7 from git import Repo
8+ from git.cmd import Git
9 except ImportError:
10 from charmhelpers.fetch import apt_install
11 apt_install("python-git")
12 from git import Repo
13+ from git.cmd import Git
14+
15
16 from git.exc import GitCommandError # noqa E402
17
18@@ -62,6 +65,13 @@
19 else:
20 dest_dir = os.path.join(os.environ.get('CHARM_DIR'), "fetched",
21 branch_name)
22+ if os.path.exists(dest_dir):
23+ # install_from when using git remotes should default to
24+ # updating the repository on a subsequent run.
25+ g = Git(dest_dir)
26+ g.pull()
27+ return dest_dir
28+
29 if not os.path.exists(dest_dir):
30 mkdir(dest_dir, perms=0o755)
31 try:

Subscribers

People subscribed via source and target branches