1
我有一個預先提交的鉤子,它使用ruby gem semver2來定義內部版本號。 gem基本上只是創建一個名爲.semver的文件,用於存儲軟件包的版本信息。Pre-commit hook修改AssemblyInfo
掛鉤根據某些日期/提交參數生成內部版本號,然後使用此信息更改AssemblyInfo.cs,然後在提交之前添加已更改的文件。
我有幾個問題在這裏:
是否有具有鉤修改我的AssemblyInfo文件就.NET而言危險?
這應該用預提交鉤子還是不同的鉤子來完成?
如何判斷此掛鉤在
--amend
,merge
和rebase
提交中的行爲不同?我怎麼能告訴這個鉤子在分支上的行爲不同?
您是否有不同的解決方案來自動構建編號?
鉤:
#!/bin/sh
#
# Append build number to semver version
#
# check semver has been initiated
if [ -f .semver ]; then
echo `semver`
else
echo `semver init`
echo `semver inc minor`
echo `semver pre 'alpha.1'`
echo `semver`
fi
# grab date string
date_str=`date +%y%m.%d.`
# grab commit count +1
build_num=$(git rev-list --since="00:00:00" HEAD --count)
let "build_num += 1"
# generate build & apply to semver
build=$date_str$build_num
semver meta $build
# define version strings
semver_str=$(semver)
ver_full=${semver_str#"v"}
cut_meta=$(cut -d "+" -f 1 <<<"$ver_full")
ver_small=$(cut -d "-" -f 1 <<<"$cut_meta")
# find AssemblyInfo & line number for AssemblyVersion
line=$(grep -n "AssemblyVersion(" "Properties/AssemblyInfo.cs")
line_num=$(cut -d ":" -f 1 <<<"$line")
# edit AssemblyVersion
new_line='[assembly: AssemblyVersion("'$ver_small'")]'
sed -i "${line_num}s/.*/$new_line/" "Properties/AssemblyInfo.cs"
# find line number for Semver
line=$(grep -n "Semver(" "Properties/AssemblyInfo.cs")
line_num=$(cut -d ":" -f 1 <<<"$line")
# edit Semver
new_line='[assembly: Semver("'$ver_full'")]'
sed -i "${line_num}s/.*/$new_line/" "Properties/AssemblyInfo.cs"
# add files
git add .semver
git add "Properties/AssemblyInfo.cs"
的AssemblyInfo.cs
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Authenticator.Properties;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("b6f9caad-fbfc-455a-8d69-f795fb9812ad")]
// This assembly uses the Semantic Versioning v2.0.0
// For more information on Semantic Versioning please see http://semver.org/
[assembly: AssemblyVersion("0.1.0")]
[assembly: Semver("0.1.0-alpha.1.0.0+1406.04.15")]