public const string COMMIT_LOG_TAG = "#COMMIT_LOG#"; // コミットログ置換対象のタグ //================================================================================ // 関数(static) //================================================================================ /// <summary> /// コミットハッシュを管理するスクリプトを生成します /// </summary> /// <example> /// <code> /// var outputPath = "Assets/Scripts/GitCommitHash.cs"; /// /// var option = new CommitLogOption /// ( /// count: 10, /// isNoMerges: false, /// format: "%h %cd %cn %s" /// ); /// /// var template = $@"public static class GitCommitHash /// {{ /// public const string COMMIT_HASH = ""{GitCommitHashCodeGenerator.COMMIT_HASH_TAG}""; /// public const string SHORT_COMMIT_HASH = ""{GitCommitHashCodeGenerator.SHORT_COMMIT_HASH_TAG}""; /// public const string COMMIT_LOG_TAG = @""{GitCommitHashCodeGenerator.COMMIT_LOG_TAG}""; /// }}"; /// /// GitCommitHashCodeGenerator.Generate( outputPath, template, option ); /// </code> /// </example> public static void Generate ( string outputPath, string template, CommitLogOption commitLogOption ) { // 出力先のフォルダが存在しない場合は作成します var dir = Path.GetDirectoryName(outputPath); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } // Git のコミットハッシュを読み込みます var commitHash = GitCommitHashLoader.LoadCommitHash(); var shortCommitHash = GitCommitHashLoader.LoadShortCommitHash(); var commitLog = GitCommitHashLoader.LoadCommitLog(commitLogOption); // コミットハッシュを埋め込んだスクリプトの文字列を作成します var code = template; code = code.Replace(COMMIT_HASH_TAG, commitHash); code = code.Replace(SHORT_COMMIT_HASH_TAG, shortCommitHash); code = code.Replace(COMMIT_LOG_TAG, commitLog); // 作成した文字列をスクリプトとして保存します File.WriteAllText(outputPath, code); AssetDatabase.Refresh(); }
/// <summary> /// Git のコミットログを読み込んで返します /// </summary> public static string LoadCommitLog(CommitLogOption option) { var count = option.Count; var isNoMerges = option.IsNoMerges; var noMergesText = isNoMerges ? "--no-merges " : string.Empty; var format = option.Format; return(LoadImpl($@"log -n {count} --date=short {noMergesText} --pretty=format:""{format}""")); }
private static void LogCommitLog() { var option = new CommitLogOption ( count: 10, isNoMerges: false, format: "%h %cd %cn %s" ); Debug.Log($"[UniGitCommitHash]\n{GitCommitHashLoader.LoadCommitLog( option )}"); }