Skip to content

Commit

Permalink
Merge pull request #150 from tacahilo/ensure-git-repository
Browse files Browse the repository at this point in the history
Check directory is empty or not for git resource
  • Loading branch information
ryotarai committed Jul 21, 2015
2 parents 8c39029 + 7846348 commit eb50b97
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/itamae/resource/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ def action_sync(options)

new_repository = false

if run_specinfra(:check_file_is_directory, attributes.destination)
run_command_in_repo(['git', 'fetch', 'origin'])
else
if check_empty_dir
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
Expand Down Expand Up @@ -67,6 +67,10 @@ def ensure_git_available
end
end

def check_empty_dir
run_command("test -z \"$(ls -A #{shell_escape(attributes.destination)})\"", error: false).success?
end

def run_command_in_repo(*args)
run_command(*args, cwd: attributes.destination)
end
Expand Down

0 comments on commit eb50b97

Please sign in to comment.