Skip to content

Commit

Permalink
Let #resolved_revision return the last fetched commit
Browse files Browse the repository at this point in the history
  • Loading branch information
soutaro committed Jan 20, 2023
1 parent 8df79b6 commit 70d3037
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
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

0 comments on commit 70d3037

Please sign in to comment.