From ba4700d253630687b3eb97b09061bd4d193416a0 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Mon, 11 Jun 2012 20:58:40 +0200 Subject: [PATCH] Fixed UpdateAssemblyInfo error when git repository exists but git.exe cannot be found. --- BuildTools/UpdateAssemblyInfo/Main.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/BuildTools/UpdateAssemblyInfo/Main.cs b/BuildTools/UpdateAssemblyInfo/Main.cs index 84df27326..f9669f062 100644 --- a/BuildTools/UpdateAssemblyInfo/Main.cs +++ b/BuildTools/UpdateAssemblyInfo/Main.cs @@ -195,8 +195,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(".")); } @@ -226,10 +230,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(); } } @@ -269,11 +275,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"); } }