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

Let #resolved_revision return the last fetched commit #1215

Merged
merged 1 commit into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion lib/rbs/collection/sources/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def resolved_revision
if commit_hash?
revision
else
setup! { git('rev-parse', revision).chomp }
setup! { git('rev-parse', "refs/remotes/origin/#{revision}").chomp }
end
end
end
Expand Down
32 changes: 32 additions & 0 deletions test/rbs/collection/sources/git_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,36 @@ def source(revision: 'b4d3b346d9657543099a35a1fd20347e75b8c523')
'repo_dir' => 'gems',
})
end

def git(*cmd, **opts)
Open3.capture3("git", *cmd, **opts).then do |out, err, status|
raise "Unexpected git status: \n\n#{err}" unless status.success?
out
end
end

def test_resolved_revision_updated_after_fetch
Dir.mktmpdir do |dir|
origin_repo = File.join(dir, "origin_repo")
Dir.mkdir(origin_repo)
git "init", chdir: origin_repo
git "config", "user.email", "[email protected]", chdir: origin_repo
git "config", "user.name", "Your Name", chdir: origin_repo
git "checkout", "-b", "main", chdir: origin_repo

git "commit", "--allow-empty", "-m", "Initial commit", chdir: origin_repo
sha_initial_commit = git("rev-parse", "HEAD", chdir: origin_repo).chomp

RBS::Collection::Sources::Git.new(name: "test", revision: "main", remote: origin_repo, repo_dir: "gems").tap do |source|
assert_equal sha_initial_commit, source.resolved_revision
end

git "commit", "--allow-empty", "-m", "Second commit", chdir: origin_repo
sha_second_commit = git("rev-parse", "HEAD", chdir: origin_repo).chomp

RBS::Collection::Sources::Git.new(name: "test", revision: "main", remote: origin_repo, repo_dir: "gems").tap do |source|
assert_equal sha_second_commit, source.resolved_revision
end
end
end
end