diff --git a/GVFS/GVFS.Common/Enlistment.cs b/GVFS/GVFS.Common/Enlistment.cs index 090a81c9e..9e40b309c 100644 --- a/GVFS/GVFS.Common/Enlistment.cs +++ b/GVFS/GVFS.Common/Enlistment.cs @@ -122,5 +122,18 @@ public bool GetTrustPackIndexesConfig() return trustPackIndexes; } + + public bool GetStatusHydrationConfig() + { + var gitProcess = this.CreateGitProcess(); + + if (gitProcess.TryGetFromConfig(GVFSConstants.GitConfig.ShowHydrationStatus, forceOutsideEnlistment: false, out var valueString) + && bool.TryParse(valueString, out var statusHydrationConfig)) + { + return statusHydrationConfig; + } + + return GVFSConstants.GitConfig.ShowHydrationStatusDefault; + } } } diff --git a/GVFS/GVFS.Common/GVFSConstants.cs b/GVFS/GVFS.Common/GVFSConstants.cs index f2f05fc02..3f3abecc4 100644 --- a/GVFS/GVFS.Common/GVFSConstants.cs +++ b/GVFS/GVFS.Common/GVFSConstants.cs @@ -42,6 +42,9 @@ public static class GitConfig /* Intended to be a temporary config to allow testing of distrusting pack indexes from cache server * before it is enabled by default. */ public const string TrustPackIndexes = GVFSPrefix + "trust-pack-indexes"; + + public const string ShowHydrationStatus = GVFSPrefix + "show-hydration-status"; + public const bool ShowHydrationStatusDefault = false; } public static class LocalGVFSConfig diff --git a/GVFS/GVFS.Common/GitStatusCache.cs b/GVFS/GVFS.Common/GitStatusCache.cs index 717e7aebc..8ef6b3743 100644 --- a/GVFS/GVFS.Common/GitStatusCache.cs +++ b/GVFS/GVFS.Common/GitStatusCache.cs @@ -52,7 +52,7 @@ public class GitStatusCache : IDisposable private object cacheFileLock = new object(); - internal static bool TEST_EnableHydrationSummary = true; + internal static bool? TEST_EnableHydrationSummaryOverride = null; public GitStatusCache(GVFSContext context, GitStatusCacheConfig config) : this(context, config.BackoffTime) @@ -341,7 +341,8 @@ private void RebuildStatusCacheIfNeeded(bool ignoreBackoff) private void UpdateHydrationSummary() { - if (!TEST_EnableHydrationSummary) + bool enabled = TEST_EnableHydrationSummaryOverride ?? this.context.Enlistment.GetStatusHydrationConfig(); + if (!enabled) { return; } diff --git a/GVFS/GVFS.Common/HealthCalculator/EnlistmentHydrationSummary.cs b/GVFS/GVFS.Common/HealthCalculator/EnlistmentHydrationSummary.cs index 02a32c2f5..03ff6147b 100644 --- a/GVFS/GVFS.Common/HealthCalculator/EnlistmentHydrationSummary.cs +++ b/GVFS/GVFS.Common/HealthCalculator/EnlistmentHydrationSummary.cs @@ -28,12 +28,12 @@ public string ToMessage() { if (!IsValid) { - return "Error calculating hydration. Run 'gvfs health' for details."; + return "Error calculating hydration summary. Run 'gvfs health' at the repository root for hydration status details."; } int fileHydrationPercent = TotalFileCount == 0 ? 0 : (100 * HydratedFileCount) / TotalFileCount; int folderHydrationPercent = TotalFolderCount == 0 ? 0 : ((100 * HydratedFolderCount) / TotalFolderCount); - return $"{fileHydrationPercent}% of files and {folderHydrationPercent}% of folders hydrated. Run 'gvfs health' for details."; + return $"{fileHydrationPercent}% of files and {folderHydrationPercent}% of folders hydrated. Run 'gvfs health' at the repository root for details."; } public static EnlistmentHydrationSummary CreateSummary( diff --git a/GVFS/GVFS.Hooks/Program.cs b/GVFS/GVFS.Hooks/Program.cs index 0bfe0da54..d48230a2a 100644 --- a/GVFS/GVFS.Hooks/Program.cs +++ b/GVFS/GVFS.Hooks/Program.cs @@ -88,8 +88,9 @@ private static void RunPreCommands(string[] args) ProcessHelper.Run("gvfs", "prefetch --commits", redirectOutput: false); break; case "status": - /* If status is being run to serialize for caching, skip the health display */ - if (!args.Any(arg => arg.StartsWith("--serialize", StringComparison.OrdinalIgnoreCase))) + /* If status is being run to serialize for caching, or if --porcelain is specified, skip the health display */ + if (!ArgsBlockHydrationStatus(args) + && ConfigurationAllowsHydrationStatus()) { /* Display a message about the hydration status of the repo */ ProcessHelper.Run("gvfs", "health --status", redirectOutput: false); @@ -98,6 +99,30 @@ private static void RunPreCommands(string[] args) } } + private static bool ArgsBlockHydrationStatus(string[] args) + { + return args.Any(arg => + arg.StartsWith("--serialize", StringComparison.OrdinalIgnoreCase) + || arg.StartsWith("--porcelain", StringComparison.OrdinalIgnoreCase)); + } + + private static bool ConfigurationAllowsHydrationStatus() + { + try + { + ProcessResult result = ProcessHelper.Run("git", $"config --get {GVFSConstants.GitConfig.ShowHydrationStatus}"); + bool hydrationStatusEnabled; + if (bool.TryParse(result.Output.Trim(), out hydrationStatusEnabled)) + { + return hydrationStatusEnabled; + } + } + catch (Exception) + { + } + return GVFSConstants.GitConfig.ShowHydrationStatusDefault; + } + private static void ExitWithError(params string[] messages) { foreach (string message in messages) diff --git a/GVFS/GVFS.UnitTests/Common/GitStatusCacheTests.cs b/GVFS/GVFS.UnitTests/Common/GitStatusCacheTests.cs index 20ea38171..59737a83f 100644 --- a/GVFS/GVFS.UnitTests/Common/GitStatusCacheTests.cs +++ b/GVFS/GVFS.UnitTests/Common/GitStatusCacheTests.cs @@ -73,7 +73,7 @@ public void SetUp() this.fileSystem, new MockGitRepo(tracer, enlistment, this.fileSystem), enlistment); - GitStatusCache.TEST_EnableHydrationSummary = false; + GitStatusCache.TEST_EnableHydrationSummaryOverride = false; } [TearDown] @@ -85,7 +85,7 @@ public void TearDown() this.gitParentPath = null; this.gvfsMetadataPath = null; this.enlistmentDirectory = null; - GitStatusCache.TEST_EnableHydrationSummary = true; + GitStatusCache.TEST_EnableHydrationSummaryOverride = null; } [TestCase]