get_git.ps1 1.1 KB

123456789101112131415161718192021222324252627
  1. if (Test-Path -Path ".\.git" -PathType Container) {
  2. # 如果 .git 目录存在
  3. $last_commit = git rev-parse HEAD 2>$null
  4. $last_tag = git describe --tags --abbrev=0 2>$null
  5. if (-not [string]::IsNullOrEmpty($last_tag)) {
  6. # 如果有标签
  7. $last_tag_commit = git rev-list -n 1 $last_tag 2>$null
  8. Set-Content -Path "commit_data.txt" -Value $last_commit -Encoding UTF8
  9. Set-Content -Path "tag_data.txt" -Value $last_tag -Encoding UTF8
  10. Set-Content -Path "tag_commit_data.txt" -Value $last_tag_commit -Encoding UTF8
  11. } else {
  12. # 如果没有标签
  13. Set-Content -Path "commit_data.txt" -Value $last_commit -Encoding UTF8
  14. New-Item -Path "tag_data.txt" -ItemType File -Force
  15. New-Item -Path "tag_commit_data.txt" -ItemType File -Force
  16. }
  17. } else {
  18. # 如果 .git 目录不存在
  19. New-Item -Path "commit_data.txt" -ItemType File -Force
  20. New-Item -Path "tag_data.txt" -ItemType File -Force
  21. New-Item -Path "tag_commit_data.txt" -ItemType File -Force
  22. }
  23. # 创建 VERSION 文件
  24. New-Item -Path "VERSION" -ItemType File -Force