-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v.utils: update
githash
to be able to get the githash of every pass…
…ed project (#21178)
- Loading branch information
Showing
4 changed files
with
70 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import v.util.version | ||
import os | ||
|
||
fn test_githash() { | ||
if !os.exists(os.join_path(@VMODROOT, '.git')) { | ||
eprintln('> skipping test due to missing V .git directory') | ||
return | ||
} | ||
sha := version.githash(@VMODROOT)! | ||
assert sha == @VCURRENTHASH | ||
|
||
git_proj_path := os.join_path(os.vtmp_dir(), 'test_githash') | ||
defer { | ||
os.rmdir_all(git_proj_path) or {} | ||
} | ||
os.execute_opt('git init ${git_proj_path}')! | ||
os.chdir(git_proj_path)! | ||
if sha_ := version.githash(git_proj_path) { | ||
assert false, 'Should not have found an unknown revision' | ||
} else { | ||
assert err.msg().contains('failed to find revision file'), err.msg() | ||
} | ||
os.execute_opt('git config user.name') or { | ||
os.execute_opt('git config user.email "ci@vlang.io"')! | ||
os.execute_opt('git config user.name "V CI"')! | ||
} | ||
os.write_file('v.mod', '')! | ||
os.execute_opt('git add .')! | ||
os.execute_opt('git commit -m "test1"')! | ||
test_rev := os.execute_opt('git rev-parse --short HEAD')!.output.trim_space() | ||
assert test_rev == version.githash(git_proj_path)! | ||
os.write_file('README.md', '')! | ||
os.execute_opt('git add .')! | ||
os.execute_opt('git commit -m "test2"')! | ||
test_rev2 := os.execute_opt('git rev-parse --short HEAD')!.output.trim_space() | ||
assert test_rev2 != test_rev | ||
assert test_rev2 == version.githash(git_proj_path)! | ||
} |