lib/itamae/resource/git.rb in itamae-1.8.0 vs lib/itamae/resource/git.rb in itamae-1.9.0
- old
+ new
@@ -31,17 +31,16 @@
cmd = ['git', 'clone']
cmd << '--recursive' if attributes.recursive
cmd << attributes.repository << attributes.destination
run_command(cmd)
new_repository = true
- else
- run_command_in_repo(['git', 'fetch', 'origin'])
end
target = if attributes.revision
get_revision(attributes.revision)
else
+ fetch_origin!
run_command_in_repo("git ls-remote origin HEAD | cut -f1").stdout.strip
end
if new_repository || target != get_revision('HEAD')
updated!
@@ -50,10 +49,11 @@
if current_branch == DEPLOY_BRANCH
run_command_in_repo("git branch -m deploy-old")
deploy_old_created = true
end
+ fetch_origin!
run_command_in_repo(["git", "checkout", target, "-b", DEPLOY_BRANCH])
if deploy_old_created
run_command_in_repo("git branch -d deploy-old")
end
@@ -79,9 +79,15 @@
run_command_in_repo("git rev-parse --abbrev-ref HEAD").stdout.strip
end
def get_revision(branch)
run_command_in_repo("git rev-list #{shell_escape(branch)} | head -n1").stdout.strip
+ end
+
+ def fetch_origin!
+ return if @origin_fetched
+ @origin_fetched = true
+ run_command_in_repo(['git', 'fetch', 'origin'])
end
end
end
end