lib/itamae/resource/git.rb in itamae-1.4.0 vs lib/itamae/resource/git.rb in itamae-1.4.1
- old
+ new
@@ -25,18 +25,18 @@
def action_sync(options)
ensure_git_available
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
get_revision(attributes.revision)
else
@@ -63,9 +63,13 @@
private
def ensure_git_available
unless run_command("which git", error: false).exit_status == 0
raise "`git` command is not available. Please install git."
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