Skip to content

Commit ac0f426

Browse files
Merge pull request #105 from codacy/ls/add-sha-prefix
2 parents 6c1123c + 6d7d3d7 commit ac0f426

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: 2.1
22

33
orbs:
4-
codacy: codacy/base@9.3.1
4+
codacy: codacy/base@12.2.0
55

66
# Re-usable blocks to reduce boilerplate in job definitions.
77
references:

spec/git-version-spec.cr

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,33 @@ require "../src/git-version"
66

77
include Utils
88
describe GitVersion do
9+
it "should match hash with hash without prefix" do
10+
tmp = InTmp.new
11+
begin
12+
git = GitVersion::Git.new("dev", "master", "feature:", "breaking:", tmp.@tmpdir)
13+
14+
tmp.exec %(git init)
15+
tmp.exec %(git checkout -b #{git.release_branch})
16+
tmp.exec %(git commit --no-gpg-sign --allow-empty -m "1")
17+
tmp.exec %(git tag "1.0.0")
18+
19+
version = git.get_new_version
20+
21+
version.should eq("1.0.1")
22+
23+
tmp.exec %(git checkout -b dev)
24+
tmp.exec %(git commit --no-gpg-sign --allow-empty -m "2")
25+
26+
tag_on_master = git.tags_by_branch("#{git.release_branch}")
27+
28+
tag_on_master.should eq(["1.0.0"])
29+
30+
hash = git.current_commit_hash
31+
hashWithoutPrefix = git.current_commit_hash_without_prefix
32+
33+
hash.should eq("sha.#{hashWithoutPrefix}")
34+
end
35+
end
936
it "should get the correct version in master and dev branch" do
1037
tmp = InTmp.new
1138

src/git-version.cr

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,13 @@ module GitVersion
7474

7575
def current_commit_hash : String
7676
cmd = "git rev-parse --verify HEAD --short"
77-
return (exec cmd)[0].rjust(7, '0')
77+
sha = (exec cmd)[0].strip
78+
return "sha." + sha
79+
end
80+
81+
def current_commit_hash_without_prefix : String
82+
cmd = "git rev-parse --verify HEAD --short"
83+
return (exec cmd)[0].strip
7884
end
7985

8086
def commits_distance(tag : String | Nil)
@@ -98,7 +104,7 @@ module GitVersion
98104
return [] of String
99105
end
100106

101-
def get_previous_tag_and_version: Tuple(String | Nil, SemanticVersion)
107+
def get_previous_tag_and_version : Tuple(String | Nil, SemanticVersion)
102108
cb = current_branch_or_tag
103109

104110
branch_tags = tags_by_branch(cb)
@@ -126,7 +132,7 @@ module GitVersion
126132
return {previous_tag, previous_version}
127133
end
128134

129-
def get_previous_version: String
135+
def get_previous_version : String
130136
lt, lv = get_previous_tag_and_version
131137
return lt ? lt : add_prefix(lv.to_s)
132138
end

0 commit comments

Comments
 (0)