Skip to content

Commit

Permalink
Merge pull request #182 from k0kubun/faster-git
Browse files Browse the repository at this point in the history
Optimize git resource for fixed revision
  • Loading branch information
ryotarai committed Dec 9, 2015
2 parents 66bf3c9 + 25f9270 commit dd2a3aa
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/itamae/resource/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,12 @@ def action_sync(options)
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

Expand All @@ -52,6 +51,7 @@ def action_sync(options)
deploy_old_created = true
end

fetch_origin!
run_command_in_repo(["git", "checkout", target, "-b", DEPLOY_BRANCH])

if deploy_old_created
Expand Down Expand Up @@ -82,6 +82,12 @@ def current_branch
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
Expand Down

0 comments on commit dd2a3aa

Please sign in to comment.