diff --git a/src/Tools/UpdateAssemblyInfo/Main.cs b/src/Tools/UpdateAssemblyInfo/Main.cs index 2113cc4901..75cbd26bd4 100644 --- a/src/Tools/UpdateAssemblyInfo/Main.cs +++ b/src/Tools/UpdateAssemblyInfo/Main.cs @@ -203,8 +203,12 @@ namespace UpdateAssemblyInfo { if (revisionNumber == null) { if (Directory.Exists(".git")) { - ReadRevisionNumberFromGit(); - ReadBranchNameFromGit(); + try { + ReadRevisionNumberFromGit(); + ReadBranchNameFromGit(); + } catch (Exception ex) { + Console.WriteLine(ex.ToString()); + } } else { Console.WriteLine("There's no git working copy in " + Path.GetFullPath(".")); } @@ -234,10 +238,12 @@ namespace UpdateAssemblyInfo } revNum++; } - revisionNumber = revNum.ToString(); p.WaitForExit(); if (p.ExitCode != 0) throw new Exception("git-rev-list exit code was " + p.ExitCode); + // Only set revisionNuber once we ensured the operation was successful, + // so that we retrieve the number from the REVISION file in case of errors + revisionNumber = revNum.ToString(); } } @@ -277,11 +283,11 @@ namespace UpdateAssemblyInfo Console.WriteLine(); Console.WriteLine("Build continues with revision number '0'..."); - revisionNumber = "0"; - gitCommitHash = "0000000000000000000000000000000000000000"; + revisionNumber = null; } if (revisionNumber == null || revisionNumber.Length == 0) { revisionNumber = "0"; + gitCommitHash = "0000000000000000000000000000000000000000"; //throw new ApplicationException("Error reading revision number"); } }