diff --git a/lib/itamae/resource/git.rb b/lib/itamae/resource/git.rb index 9214ab2e..60c86c1e 100644 --- a/lib/itamae/resource/git.rb +++ b/lib/itamae/resource/git.rb @@ -72,7 +72,11 @@ def check_empty_dir end def run_command_in_repo(*args) - run_command(*args, cwd: attributes.destination) + unless args.last.is_a?(Hash) + args << {} + end + args.last[:cwd] = attributes.destination + run_command(*args) end def current_branch @@ -80,7 +84,11 @@ def current_branch end def get_revision(branch) - run_command_in_repo("git rev-list #{shell_escape(branch)} | head -n1").stdout.strip + result = run_command_in_repo("git rev-list #{shell_escape(branch)}", error: false) + unless result.exit_status == 0 + fetch_origin! + end + run_command_in_repo("git rev-list #{shell_escape(branch)}").stdout.lines.first.strip end def fetch_origin!