public void FetchWithoutConflict(string remote, string branchName) { // To get ssh to work with hg, we need to ensure ssh.exe exists in the path and the HOME environment variable is set. // NOTE: Although hge.exe accepts the path to ssh.exe via a --ssh parameter, it cannot handle any whitespace // This doesn't work for us since ssh.exe is located under Program Files in typical Kudu scenarios. _hgExecutable.SetHomePath(_homePath); string currentPath = System.Environment.GetEnvironmentVariable(PATH_KEY); char sep = Path.PathSeparator; currentPath = currentPath.TrimEnd(sep) + sep + Path.GetDirectoryName(PathUtilityFactory.Instance.ResolveSSHPath()); _hgExecutable.EnvironmentVariables[PATH_KEY] = currentPath; ITracer tracer = _traceFactory.GetTracer(); bool retried = false; // Whitespace in branch name is legal in Mercurial. // We need double quotes around branchName. string branchNameWithQuotes = "\"" + branchName + "\""; fetch: try { _hgExecutable.Execute(tracer, "pull {0} --branch {1} --noninteractive", remote, branchNameWithQuotes, PathUtilityFactory.Instance.ResolveSSHPath()); } catch (CommandLineException exception) { string branchNotFoundMessage = String.Format(CultureInfo.InvariantCulture, "abort: unknown branch '{0}'!", branchName); string recoverRequiredMessage = "abort: abandoned transaction found - run hg recover!"; string exceptionMessage = (exception.Message ?? String.Empty).TrimEnd(); if (exceptionMessage.StartsWith(branchNotFoundMessage, StringComparison.OrdinalIgnoreCase)) { throw new BranchNotFoundException(branchNameWithQuotes, exception); } else if (!retried && exceptionMessage.IndexOf(recoverRequiredMessage, StringComparison.OrdinalIgnoreCase) != -1) { // Check if the previous fetch failed with a message to recover. retried = true; _hgExecutable.Execute(tracer, "recover"); goto fetch; } throw; } _hgExecutable.Execute(tracer, "update --clean {0}", branchNameWithQuotes); }