diff --git a/Source/Tools/Flax.Build/Deps/Dependency.cs b/Source/Tools/Flax.Build/Deps/Dependency.cs index 848f2a2a9..fbb505dd1 100644 --- a/Source/Tools/Flax.Build/Deps/Dependency.cs +++ b/Source/Tools/Flax.Build/Deps/Dependency.cs @@ -158,7 +158,7 @@ namespace Flax.Deps } /// - /// Clones the git repository from the remote url. + /// Clones the git repository from the remote url (shallow clone). /// /// The local path for close. /// The remote url. @@ -180,6 +180,29 @@ namespace Flax.Deps } } + /// + /// Clones the git repository from the remote url. + /// + /// The local path for close. + /// The remote url. + /// The custom arguments to add to the clone command. + /// True if initialize submodules of the repository (recursive). + public static void CloneGitRepoFastSince(string path, string url, DateTime time, string args = null, bool submodules = false) + { + if (!Directory.Exists(Path.Combine(path, ".git"))) + { + string cmdLine = string.Format("clone \"{0}\" \"{1}\" --shallow-since={2}", url, path, time.ToString("s")); + if (args != null) + cmdLine += " " + args; + if (submodules) + cmdLine += " --recurse-submodules"; + + Utilities.Run("git", cmdLine, null, path, Utilities.RunOptions.DefaultTool); + if (submodules) + Utilities.Run("git", "submodule update --init --recursive", null, path, Utilities.RunOptions.DefaultTool); + } + } + /// /// Clones the git repository from the remote url (clones a single branch). /// @@ -247,14 +270,32 @@ namespace Flax.Deps Utilities.Run("git", "reset --hard", null, path, Utilities.RunOptions.DefaultTool); } + /// + /// Resets to the specific commit, optionally fetching the commit from remote. + /// Note: Fetching requires server-side support, may not work with all servers. + /// + /// The local path that contains git repository. + /// The full hash of the commit. + /// Fetch the commit from remote. + public static void GitResetToCommit(string path, string commit, bool fetch = false) + { + if (fetch) + { + // This requires server-side configuration uploadpack.allowReachableSHA1InWant to be enabled + Utilities.Run("git", $"fetch --depth=1 \"{path}\" {commit}", null, path, Utilities.RunOptions.ConsoleLogOutput); + } + Utilities.Run("git", $"reset --hard {commit}", null, path, Utilities.RunOptions.DefaultTool); + } + /// /// Builds the cmake project. /// /// The path. + /// The configuration preset. /// Custom environment variables to pass to the child process. - public static void BuildCmake(string path, Dictionary envVars = null) + public static void BuildCmake(string path, string config = "Release", Dictionary envVars = null) { - Utilities.Run("cmake", "--build . --config Release", null, path, Utilities.RunOptions.DefaultTool, envVars); + Utilities.Run("cmake", $"--build . --config {config}", null, path, Utilities.RunOptions.DefaultTool, envVars); } ///