Merge pull request #472 from ansible/git-cleanup

Git cleanup
This commit is contained in:
Toshio Kuratomi 2014-12-09 07:39:51 -08:00
commit abff6c2582

View file

@ -272,7 +272,7 @@ def get_submodule_versions(git_path, module, dest, version='HEAD'):
return submodules
def clone(git_path, module, repo, dest, remote, depth, version, bare,
reference, recursive):
reference):
''' makes a new git repo if it does not already exist '''
dest_dirname = os.path.dirname(dest)
try:
@ -284,8 +284,6 @@ def clone(git_path, module, repo, dest, remote, depth, version, bare,
cmd.append('--bare')
else:
cmd.extend([ '--origin', remote ])
if recursive:
cmd.extend([ '--recursive' ])
if is_remote_branch(git_path, module, dest, repo, version) \
or is_remote_tag(git_path, module, dest, repo, version):
cmd.extend([ '--branch', version ])
@ -434,7 +432,7 @@ def get_head_branch(git_path, module, dest, remote, bare=False):
f.close()
return branch
def fetch(git_path, module, repo, dest, version, remote, bare, track_submodules, recursive):
def fetch(git_path, module, repo, dest, version, remote, bare):
''' updates repo from remote sources '''
out_acc = []
err_acc = []
@ -459,12 +457,6 @@ def fetch(git_path, module, repo, dest, version, remote, bare, track_submodules,
out_acc.append(out2)
err_acc.append(err2)
if recursive:
(rc, out3, err3) = submodule_update(git_path, module, dest, track_submodules)
if rc != 0:
module.fail_json(msg="Failed to update submodules: %s" % "".join(out3, err3))
out_acc.append(out3)
err_acc.append(err3)
return (rc, ''.join(out_acc), ''.join(err_acc))
@ -484,6 +476,7 @@ def submodules_fetch(git_path, module, remote, track_submodules, dest):
if not os.path.exists(os.path.join(dest, path, '.git')):
changed = True
break
### FIXME: Add the submodule hostkeys here as well
# Check for updates to existing modules
if not changed:
@ -535,7 +528,7 @@ def submodule_update(git_path, module, dest, track_submodules):
return (rc, out, err)
def switch_version(git_path, module, dest, remote, version, recursive, track_submodules):
def switch_version(git_path, module, dest, remote, version):
cmd = ''
if version != 'HEAD':
if is_remote_branch(git_path, module, dest, remote, version):
@ -560,10 +553,6 @@ def switch_version(git_path, module, dest, remote, version, recursive, track_sub
module.fail_json(msg="Failed to checkout %s" % (version))
else:
module.fail_json(msg="Failed to checkout branch %s" % (branch))
if recursive:
(rc, out2, err2) = submodule_update(git_path, module, dest, track_submodules)
out1 += out2
err1 += err1
return (rc, out1, err1)
# ===========================================
@ -645,7 +634,7 @@ def main():
remote_head = get_remote_head(git_path, module, dest, version, repo, bare)
module.exit_json(changed=True, before=before, after=remote_head)
# there's no git config, so clone
clone(git_path, module, repo, dest, remote, depth, version, bare, reference, recursive)
clone(git_path, module, repo, dest, remote, depth, version, bare, reference)
repo_updated = True
elif not update:
# Just return having found a repo already in the dest path
@ -676,16 +665,16 @@ def main():
repo_updated = False
else:
repo_updated = False
if repo_updated is not False:
if repo_updated is None:
if module.check_mode:
module.exit_json(changed=True, before=before, after=remote_head)
fetch(git_path, module, repo, dest, version, remote, bare, track_submodules, recursive)
fetch(git_path, module, repo, dest, version, remote, bare)
repo_updated = True
# switch to version specified regardless of whether
# we cloned or pulled
if repo_updated and not bare:
switch_version(git_path, module, dest, remote, version, recursive, track_submodules)
# we got new revisions from the repository
if not bare:
switch_version(git_path, module, dest, remote, version)
# Deal with submodules
submodules_updated = False
@ -706,14 +695,16 @@ def main():
after = get_version(module, git_path, dest)
changed = False
if before != after or local_mods:
changed = True
elif submodules_updated:
if before != after or local_mods or submodules_updated:
changed = True
# cleanup the wrapper script
if ssh_wrapper:
try:
os.remove(ssh_wrapper)
except OSError:
# No need to fail if the file already doesn't exist
pass
module.exit_json(changed=changed, before=before, after=after)