Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If git rev-list fails, do git fetch origin #205

Merged
merged 2 commits into from
Apr 7, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions lib/itamae/resource/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,23 @@ 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
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
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!
Expand Down