Skip to content

Commit 21047b9

Browse files
committed
Avoid overriding branch references
In case the repo is currently at a different branch than the one to be changed to, git reset would modify the current branch ref, so future usages of that branch don't work anymore (they all point to the same commit ref).
1 parent fbff68d commit 21047b9

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

lib/pmdtester/builders/project_builder.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def run_as_script(path, command)
8989
def execute_reset_cmd(type, tag)
9090
case type
9191
when 'git'
92-
reset_cmd = "git reset --hard #{tag}"
92+
reset_cmd = "git checkout #{tag}; git reset --hard #{tag}"
9393
when 'hg'
9494
reset_cmd = "hg up #{tag}"
9595
end

test/test_project_builder.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ def setup
1212

1313
def test_clone
1414
expect_clone('checkstyle', 'git', 'https://github.com/checkstyle/checkstyle',
15-
'git reset --hard master')
15+
'git checkout master; git reset --hard master')
1616
expect_clone('spring-framework', 'git', 'https://github.com/spring-projects/spring-framework',
17-
'git reset --hard v5.0.6.RELEASE')
17+
'git checkout v5.0.6.RELEASE; git reset --hard v5.0.6.RELEASE')
1818

1919
project_builder = PmdTester::ProjectBuilder.new(@projects)
2020
project_builder.clone_projects

0 commit comments

Comments
 (0)