private static bool integrateInDiffTool(string applicationFullPath) { IIntegratedDiffTool diffTool = createDiffTool(); DiffToolIntegration integration = new DiffToolIntegration(); try { integration.Integrate(diffTool, applicationFullPath); } catch (Exception ex) { if (ex is DiffToolNotInstalledException) { string message = String.Format( "{0} is not installed. It must be installed at least for the current user. Application cannot start", diffTool.GetToolName()); MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { string message = String.Format("{0} integration failed. Application cannot start. See logs for details", diffTool.GetToolName()); MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); ExceptionHandlers.Handle(String.Format("Cannot integrate \"{0}\"", diffTool.GetToolName()), ex); } return(false); } finally { GitTools.TraceGitConfiguration(); } return(true); }
public static void AddCustomActions(string scriptPath) { string roamingPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); string configFilePath = Path.Combine(roamingPath, SettingsPath); if (!File.Exists(configFilePath)) { throw new GitExtensionsIntegrationHelperException("Cannot find Git Extensions configuration file"); } string gitbash = Path.Combine(GitTools.GetBinaryFolder(), Constants.BashFileName); if (!File.Exists(gitbash)) { throw new GitExtensionsIntegrationHelperException("Cannot find git bash"); } // load XML from disk XDocument document = XDocument.Load(configFilePath); // find a placeholder for scripts XElement ownScripts = document? .Descendants("item") .FirstOrDefault(x => x.Descendants("string").Any(y => y.Value == "ownScripts")); XElement ownScriptsValue = ownScripts?.Element("value")?.Element("string"); if (ownScriptsValue == null) { throw new GitExtensionsIntegrationHelperException("Unexpected format of Git Extensions configuration file"); } // deserialize XML XDocument scripts = XDocument.Parse(ownScriptsValue.Value); if (scripts == null) { throw new GitExtensionsIntegrationHelperException("Unexpected format of Git Extensions configuration file"); } Debug.Assert(document != null); string name = Constants.CreateMergeRequestCustomActionName; // delete previously added element IntegrationHelper.DeleteElements(scripts, "ScriptInfo", "Name", new string[] { name }); // add element int maxHotKeyNumber = getCurrentMaximumHotKeyNumber(scripts); XElement[] elements = new XElement[] { getCreateMergeRequestElement(name, scriptPath, maxHotKeyNumber, gitbash) }; if (!IntegrationHelper.AddElements(scripts, "ArrayOfScriptInfo", elements)) { throw new GitExtensionsIntegrationHelperException("Unexpected format of Git Extensions configuration file"); } // serialize XML and save to disk ownScriptsValue.Value = scripts.ToString(); document.Save(configFilePath); }
public void PerformRelease(BuildState state, AbsolutePath changeLogFile, Action <BuildType, string> buildAction) { var releaseId = Guid.NewGuid(); var releaseBranchTag = "_release-state-" + releaseId; var stagingBranchTag = "_staging-state-" + releaseId; EnsureOnReleaseStagingBranch(state); GitTools.Tag(stagingBranchTag, state.ReleaseStagingBranch); try { if (ChangeLogGenerator.TryPrepareChangeLogForRelease(state, changeLogFile, out var sectionFile)) { GitTools.Commit($"Updated change log for release {state.Version.MajorMinorPatch}"); } // record the current master branch state. // We will use that later to potentially undo any changes we made during that build. GitTools.Tag(releaseBranchTag, state.ReleaseTargetBranch); try { // this takes the current staging branch state and merges it into // the release branch (usually master). This changes the active // branch of the working copy. GitTools.MergeRelease(state.ReleaseTargetBranch, state.ReleaseStagingBranch); // attempt to build the release again. ValidateBuild(buildAction, BuildType.Release, sectionFile); } catch { Logger.Error("Error: Unable to build the release on the release branch. Attempting to roll back changes on release branch."); GitTools.Reset(GitTools.ResetType.Hard, releaseBranchTag); GitTools.Checkout(stagingBranchTag); GitTools.ResetBranch(state.ReleaseStagingBranch, stagingBranchTag); throw; } finally { GitTools.DeleteTag(releaseBranchTag); } } catch { // In case of errors, roll back all commits and restore the current state // to be back on the release-staging branch. GitTools.Checkout(stagingBranchTag); GitTools.ResetBranch(state.ReleaseStagingBranch, stagingBranchTag); throw; } finally { GitTools.DeleteTag(stagingBranchTag); } }
public void ContinueOnDevelopmentBranch(BuildState state) { EnsureNoUncommittedChanges(); GitTools.Checkout(state.DevelopmentBranch); GitTools.Merge(state.ReleaseStagingBranch); UpdateVersionNumbers?.Invoke(this, BuildType.Development); }
private void BuildApp() { const string fileName = "TSK"; #if UNITY_STANDALONE_WIN const string FolderName = "PC"; const string packName = fileName + ".exe"; #elif UNITY_STANDALONE_OSX const string FolderName = "MAC"; const string packName = fileName + ".app"; #elif UNITY_ANDROID const string FolderName = "AND"; const string packName = fileName + ".apk"; #elif UNITY_IOS const string FolderName = "IOS"; const string packName = fileName + ".ipa"; #endif #if RY_DEBUG const BuildOptions bo = BuildOptions.AllowDebugging | BuildOptions.ConnectWithProfiler; #else const BuildOptions bo = BuildOptions.None; #endif //var verInfo = VersionMgr.LoadAppVersion(); VersionMgr.SaveAppVersion(GitTools.getVerInfo()); AssetDatabase.Refresh(); //清空PC执行文件目录的缓存文件。 string ProductPath = Application.dataPath + "/../../Products"; string ProductPCPath = Path.Combine(ProductPath, FolderName); string BuildName = ProductPCPath + "/" + packName; if (!Directory.Exists(ProductPath)) { Directory.CreateDirectory(ProductPath); } if (!Directory.Exists(ProductPCPath)) { Directory.CreateDirectory(ProductPCPath); } //开始打游戏包 BuildPipeline.BuildPlayer(new string[] { "Assets/Scenes/ZERO.unity", }, BuildName, AssetPacker.buildTarget, bo); #if UNITY_STANDALONE AssetPacker.Log("Coping Essets ..."); SystemTools.CopyDirectory(Application.dataPath + "/../Essets", ProductPCPath + "/Essets"); #endif #if UNITY_IOS XCodePostProcess.OnPostProcessBuild(BuildName); #endif AssetPacker.Log("Build Done: " + BuildName); }
public void PushStagingBranch() { var versionInfo = FetchVersion(); var stageBranchName = string.Format(build.ReleaseStagingBranchPattern, versionInfo.MajorMinorPatch, versionInfo.Major, versionInfo.Minor, versionInfo.Patch); if (!string.IsNullOrEmpty(build.PushTarget)) { Logger.Info("Publishing staging branch to public source repository."); GitTools.Push(build.PushTarget, stageBranchName); } }
public void PathNormalize() { var sd = Environment.SystemDirectory; if (string.IsNullOrEmpty(sd)) { return; // Not on Windows } var normalized = GitTools.GetNormalizedFullPath(sd); Assert.AreEqual(normalized, GitTools.GetNormalizedFullPath(sd.ToUpperInvariant())); Assert.AreEqual(normalized, GitTools.GetNormalizedFullPath(sd.ToLowerInvariant())); }
// @} ILocalGitCommitStorage // @{ IGitRepository async public Task <bool> ContainsSHAAsync(string sha) { if (_cached_existingSha.Contains(sha)) { return(true); } if (!_isDisposed && await GitTools.DoesEntityExistAtPathAsync(_processManager, Path, sha)) { _cached_existingSha.Add(sha); return(true); } return(false); }
static public void PackAssets() { AssetDatabase.RemoveUnusedAssetBundleNames(); Artwork.UIChecker.ClearIconReference(); AssetDatabase.Refresh(); BuildPipeline.BuildAssetBundles(EditorStreamingAssetsPath, options, buildTarget); // 更新资源版本号 VersionMgr.SaveAssetVersion(GitTools.getVerInfo()); AssetDatabase.Refresh(); Log("BuildAssetBundles success.\n => {0}", EditorStreamingAssetsPath); }
private static IEnumerable <string> findTargetBranch(string path, string remoteSourceBranch) { for (int iDepth = 0; iDepth < Constants.MaxCommitDepth; ++iDepth) { string sha = String.Format("{0}{1}", remoteSourceBranch, new string('^', iDepth)); IEnumerable <string> refs = GitTools.GetRemotePointsAt(path, sha) .Where(x => x != remoteSourceBranch) .Where(x => x != String.Format("{0}HEAD", RemoteOrigin)); if (refs.Any()) { return(refs); } } return(new string[] { String.Format("{0}master", RemoteOrigin) }); }
private static void disableSSLVerification() { if (Program.Settings.DisableSSLVerification) { try { GitTools.DisableSSLVerification(); Program.Settings.DisableSSLVerification = false; } catch (GitTools.SSLVerificationDisableException ex) { ExceptionHandlers.Handle("Cannot disable SSL verification", ex); } } }
private static string getFetchArguments(string sha, bool shallow) { if (sha == null) { return(String.Format(" --progress {0} {1}", GitTools.SupportsFetchNoTags() ? "--no-tags" : String.Empty, GitTools.SupportsFetchAutoGC() ? "--no-auto-gc" : String.Empty)); } return(String.Format(" --progress {0} {1} {2} {3}", String.Format("origin {0}:refs/keep-around/{0}", sha), shallow ? "--depth=1" : String.Empty, GitTools.SupportsFetchNoTags() ? "--no-tags" : String.Empty, GitTools.SupportsFetchAutoGC() ? "--no-auto-gc" : String.Empty)); }
void ValidateBuild(Action <BuildType, string> runBuildTarget, BuildType t, string path) { if (runBuildTarget == null) { throw new ArgumentException("RunBuildTarget action is not configured."); } EnsureNoUncommittedChanges(); Logger.Info("Running target build script."); runBuildTarget(t, path); Logger.Info("Restoring original assembly version files."); GitTools.Reset(GitTools.ResetType.Hard); EnsureNoUncommittedChanges(); }
/// <summary> /// Splits passed url in parts and stores in object properties /// <summary> public static ParsedNewMergeRequestUrl Parse(string url) { if (url.Length > MaxUrlLength) { throw new UriFormatException("Too long URL"); } Match m = url_re.Match(url); if (!m.Success) { throw new UriFormatException("Failed to parse URL"); } Group path = m.Groups["Repository"]; Group sourceBranch = m.Groups["SourceBranch"]; if (!path.Success || !sourceBranch.Success) { throw new UriFormatException("Unsupported URL format"); } ProjectKey?projectKey = GitTools.GetRepositoryProjectKey(path.Value); if (!projectKey.HasValue) { throw new UriFormatException(String.Format("\"{0}\" is not a git repository", path.Value)); } // sourceBranch can be one of the following: // - br_foo // - origin/br_foo // - 53ff02a // Resolve all these cases to origin/br_foo here. string remoteSourceBranch = getRemoteSourceBranch(path.Value, sourceBranch.Value); if (String.IsNullOrEmpty(remoteSourceBranch)) { throw new UriFormatException(String.Format("\"{0}\" does not point to a remote branch", sourceBranch.Value)); } string sourceBranchName = trimRemoteOrigin(remoteSourceBranch); IEnumerable <string> targetBranchName = findTargetBranch(path.Value, remoteSourceBranch) .Select(fullName => trimRemoteOrigin(fullName)); return(new ParsedNewMergeRequestUrl(projectKey.Value, sourceBranchName, targetBranchName)); }
public void PrepareStagingBranch(BuildState state) { if (state == null) { throw new ArgumentNullException(nameof(state)); } var versionInfo = FetchVersion(); if (versionInfo.BranchName == state.ReleaseTargetBranch) { throw new Exception( $@"Cannot initiate a release from the release-target branch. Switch to a develop or release-xxx branch before continuing. Based on the current version information I expect to be on branch '{state.DevelopmentBranch}', but detected branch '{versionInfo.BranchName}' instead"); } // if on development branch, create a release branch. // if you work in a support-xx branch, treat it as your develop-branch. var stageBranchName = state.ReleaseStagingBranch; if (versionInfo.BranchName == state.DevelopmentBranch) { if (GitTools.CheckBranchExists(stageBranchName)) { Logger.Info($"Switching to existing staging branch from {versionInfo.BranchName} as branch {stageBranchName}"); GitTools.Checkout(stageBranchName); } else { Logger.Info($"Creating new staging branch from current branch {versionInfo.BranchName} as branch {stageBranchName}"); GitTools.Branch(stageBranchName); UpdateVersionNumbers?.Invoke(this, BuildType.Staging); } } else { if (versionInfo.BranchName != stageBranchName) { throw new Exception( $@"This command must be exist run from the development branch or an active release branch. Based on the current version information I expect to be on branch '{state.ReleaseStagingBranch}', but detected branch '{versionInfo.BranchName}' instead"); } } }
public void WalkCommits() { using var repo = GitRepository.Open(typeof(GitRepositoryTests).Assembly.Location); foreach (var c in repo.Commits.Take(20)) { TestContext.WriteLine($"Commit {c.Id:x8} - {GitTools.FirstLine(c.Message)}"); if (c.Parent != null) { TestContext.WriteLine($" -parent {c.Parent?.Id} - {GitTools.FirstLine(c.Parent?.Message)}"); } TestContext.WriteLine($" -tree {c.Tree?.Id}"); foreach (var v in c.Tree !) { TestContext.WriteLine($" - {v.Name}"); } } }
private static ProjectKey?getRepositoryProjectKey(string path, LocalCommitStorageType type) { if (type == LocalCommitStorageType.FileStorage) { return(FileStorageUtils.GetFileStorageProjectKey(path)); } ProjectKey?key = GitTools.GetRepositoryProjectKey(path); if (key == null) { return(null); } bool isShallowRepository = File.Exists(Path.Combine(path, ".git", "shallow")); bool isAskingForShallowRepository = type == LocalCommitStorageType.ShallowGitRepository; return(isShallowRepository == isAskingForShallowRepository ? key : null); }
public async Task WalkCommitsAsync() { using var repo = GitRepository.Open(typeof(GitRepositoryTests).Assembly.Location); await foreach (var c in repo.Commits.Take(20)) { TestContext.WriteLine($"Commit {c.Id:x10} - {GitTools.FirstLine(c.Message)}"); TestContext.WriteLine($"Author: {c.Author?.ToString() ?? "-"}"); if (c.Parent != null) { TestContext.WriteLine($" -parent {c.Parent?.Id} - {GitTools.FirstLine(c.Parent?.Message)}"); } TestContext.WriteLine($" -tree {c.Tree.Id}"); foreach (var v in c.Tree) { TestContext.WriteLine($" - {v.Name}"); } } }
public async Task WalkCommitsViaObjectRepository() { using var repo = GitRepository.Open(typeof(GitRepositoryTests).Assembly.Location); //GC.KeepAlive(repo.Configuration.Identity); await foreach (var c in repo.ObjectRepository.GetAll <GitCommit>(new HashSet <GitId>())) { TestContext.WriteLine($"Commit {c.Id} - {GitTools.FirstLine(c.Message)}"); if (c.Parent != null) { TestContext.WriteLine($" -parent {c.Parent?.Id} - {GitTools.FirstLine(c.Parent?.Message)}"); } TestContext.WriteLine($" -tree {c.Tree?.Id}"); foreach (var v in c.Tree !) { TestContext.WriteLine($" - {v.Name}"); } } }
///<summary> /// Handle exceptions caused by SSL certificate problem /// Throw InteractiveUpdaterException on unrecoverable errors. ///</summary> private bool handleSSLCertificateProblem() { if (!isGlobalSSLFixAllowed()) { Trace.TraceInformation("[GitInteractiveUpdater] User rejected to disable SSl certificate verification"); return(false); } Trace.TraceInformation("[GitInteractiveUpdater] User agreed to disable SSl certificate verification"); try { GitTools.DisableSSLVerification(); } catch (GitTools.SSLVerificationDisableException ex) { throw new LocalCommitStorageUpdaterFailedException("Cannot change global http.verifySSL setting", ex); } Trace.TraceInformation("[GitInteractiveUpdater] SSL certificate verification disabled"); return(true); }
async private Task handleAuthenticationFailedException(Func <Task> command) { string configKey = "credential.interactive"; string configValue = "always"; GitTools.ConfigScope scope = _gitRepository.ExpectingClone ? GitTools.ConfigScope.Global : GitTools.ConfigScope.Local; string path = _gitRepository.ExpectingClone ? String.Empty : _gitRepository.Path; IEnumerable <string> prevValue = GitTools.GetConfigKeyValue(scope, configKey, path); string prevInteractiveMode = prevValue.Any() ? prevValue.First() : null; // `null` to unset try { GitTools.SetConfigKeyValue(scope, configKey, configValue, path); await command(); } finally { GitTools.SetConfigKeyValue(scope, configKey, prevInteractiveMode, path); } }
/// <summary> /// Throws DiffToolNotInstalledException if diff tool is not installed /// Throws DiffToolIntegrationException if integration failed /// </summary> public void Integrate(IIntegratedDiffTool diffTool, string self) { AppFinder.AppInfo appInfo = AppFinder.GetApplicationInfo(diffTool.GetToolRegistryNames()); if (appInfo == null || !isInstalled(appInfo.InstallPath)) { throw new DiffToolNotInstalledException("Diff tool not installed"); } string toolpath = appInfo.InstallPath; Trace.TraceInformation(String.Format("Diff Tool installed at: {0}", toolpath)); registerInGit(diffTool, toolpath); try { registerInTool(diffTool, self); } catch (DiffToolIntegrationException) { Trace.TraceError(String.Format("Cannot register the application in \"{0}\"", Constants.GitDiffToolName)); try { string key = String.Format("difftool.{0}.cmd", Constants.GitDiffToolName); GitTools.SetConfigKeyValue(GitTools.ConfigScope.Global, key, null, String.Empty); } catch (ExternalProcessSystemException) { Trace.TraceError(String.Format("Cannot remove \"{0}\" from git config", Constants.GitDiffToolName)); } catch (ExternalProcessFailureException) { Trace.TraceError(String.Format("Cannot remove \"{0}\" from git config", Constants.GitDiffToolName)); } throw; } }
private static bool prepareGitEnvironment() { if (!GitTools.IsGit2Installed()) { MessageBox.Show( "Git for Windows (version 2) is not installed. " + "It must be installed at least for the current user. Application cannot start.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } string pathEV = System.Environment.GetEnvironmentVariable("PATH"); System.Environment.SetEnvironmentVariable("PATH", pathEV + ";" + GitTools.GetBinaryFolder()); Trace.TraceInformation(String.Format("Updated PATH variable: {0}", System.Environment.GetEnvironmentVariable("PATH"))); System.Environment.SetEnvironmentVariable("GIT_TERMINAL_PROMPT", "0"); Trace.TraceInformation("Set GIT_TERMINAL_PROMPT=0"); Trace.TraceInformation(String.Format("TEMP variable: {0}", System.Environment.GetEnvironmentVariable("TEMP"))); return(true); }
public static void AddCustomActions(string scriptPath) { string gitbash = Path.Combine(GitTools.GetBinaryFolder(), Constants.BashFileName); if (!File.Exists(gitbash)) { throw new SourceTreeIntegrationHelperException("Cannot find git bash"); } string roamingPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); string configFilePath = Path.Combine(roamingPath, SettingsPath); string configFolder = Path.GetDirectoryName(configFilePath); if (!Directory.Exists(configFolder)) { throw new SourceTreeIntegrationHelperException("Cannot find a folder for Source Tree settings"); } // load XML from disk XDocument scripts = File.Exists(configFilePath) ? XDocument.Load(configFilePath) : new XDocument(new XElement("ArrayOfCustomAction")); Debug.Assert(scripts != null); string name = Constants.CreateMergeRequestCustomActionName; // delete previously added element IntegrationHelper.DeleteElements(scripts, "CustomAction", "Caption", new string[] { name }); // add element XElement[] elements = new XElement[] { getCreateMergeRequestElement(scriptPath, gitbash) }; if (!IntegrationHelper.AddElements(scripts, "ArrayOfCustomAction", elements)) { throw new SourceTreeIntegrationHelperException("Unexpected format of Source Tree configuration file"); } // save to disk scripts.Save(configFilePath); }
public void ValidateBuildState() { GitTools.CheckBranchExists(developBranch); GitTools.CheckBranchExists(ReleaseTargetBranch); }
/// <summary> /// Throws ExternalProcessFailureException/ExternalProcessSystemException if registration failed /// </summary> private void registerInGit(IIntegratedDiffTool diffTool, string toolpath) { string value = getGitCommand(diffTool, toolpath); GitTools.SetConfigKeyValue(GitTools.ConfigScope.Global, Constants.GitDiffToolConfigKey, value, String.Empty); }
public void TreeReplacements() { using (GitClient client = new GitClient()) { string dir = GitTools.GetTruePath(GetTempPath(), true); client.Init(dir); GitStatusArgs sa = new GitStatusArgs(); sa.GenerateVersionedDirs = true; sa.IncludeUnmodified = true; sa.IncludeIgnored = true; // Directories with 0 files are ignored sa.IncludeUnversioned = true; BuildGreek(dir); foreach (string[] k in GreekTree()) { string p = Path.Combine(dir, k[0]); if (File.Exists(p)) { client.Stage(p); } } client.Commit(dir); Directory.Delete(Path.Combine(dir, "A"), true); File.WriteAllText(Path.Combine(dir, "A"), "'A' file"); File.Delete(Path.Combine(dir, "mu")); Directory.CreateDirectory(Path.Combine(dir, "mu")); File.WriteAllText(Path.Combine(dir, "mu/AAAA"), "AAAA file"); List <string> paths = new List <string>(); int n = 0; foreach (string[] s in GreekTree()) { paths.Add(GitTools.GetNormalizedFullPath(Path.Combine(dir, s[0]))); } paths.Add(dir); paths.Add(Path.Combine(dir, "mu")); paths.Add(Path.Combine(dir, "mu\\AAAA")); /* Empty dirs are not versioned, so not reported deleted */ paths.Remove(Path.Combine(dir, "A\\C")); paths.Remove(Path.Combine(dir, "A\\B\\F")); List <string> paths2 = new List <string>(paths); n = 0; client.Status(dir, sa, delegate(object sender, GitStatusEventArgs e) { Assert.IsTrue(GitTools.IsNormalizedFullPath(e.FullPath)); Assert.IsTrue(paths.Remove(e.FullPath), "Can remove {0}", e.FullPath); Assert.IsFalse(e.IndexModified); Assert.IsFalse(e.WorkingDirectoryModified); n++; }); Assert.AreEqual(21, n); Assert.AreEqual(0, paths.Count); client.Status(dir, sa, delegate(object sender, GitStatusEventArgs e) { switch (e.WorkingDirectoryStatus) { case GitStatus.New: case GitStatus.Deleted: case GitStatus.TypeChanged: client.Stage(e.FullPath); break; default: if (e.WorkingDirectoryModified) { goto case GitStatus.New; } break; } }); paths = new List <string>(paths2); n = 0; client.Status(dir, sa, delegate(object sender, GitStatusEventArgs e) { Assert.IsTrue(GitTools.IsNormalizedFullPath(e.FullPath)); Assert.IsTrue(paths.Remove(e.FullPath), "Can remove {0}", e.FullPath); Assert.IsFalse(e.IndexModified); Assert.IsFalse(e.WorkingDirectoryModified); n++; }); Assert.AreEqual(21, n); Assert.AreEqual(0, paths.Count); client.Status(dir, sa, delegate(object sender, GitStatusEventArgs e) { switch (e.IndexStatus) { case GitStatus.New: case GitStatus.Deleted: case GitStatus.TypeChanged: client.Unstage(e.FullPath); break; } }); } }
public void FullStatus() { using (GitClient client = new GitClient()) { string dir = GitTools.GetTruePath(GetTempPath(), true); client.Init(dir); GitStatusArgs sa = new GitStatusArgs(); sa.GenerateVersionedDirs = true; sa.IncludeUnmodified = true; sa.IncludeIgnored = true; // Directories with 0 files are ignored sa.IncludeDirectories = true; BuildGreek(dir); { var paths = new HashSet <string>(StringComparer.OrdinalIgnoreCase); int n = 0; foreach (string[] s in GreekTree()) { paths.Add(GitTools.GetNormalizedFullPath(Path.Combine(dir, s[0]))); } paths.Add(dir); n = 0; client.Status(dir, sa, delegate(object sender, GitStatusEventArgs e) { Assert.IsTrue(GitTools.IsNormalizedFullPath(e.FullPath)); Assert.IsTrue(paths.Remove(e.FullPath), "Can remove {0}", e.FullPath); if (e.NodeKind == GitNodeKind.File) { Assert.AreEqual(GitStatus.None, e.IndexStatus, "Invalid index status on {0}", e.RelativePath); Assert.AreEqual(GitStatus.New, e.WorkingDirectoryStatus, "Invalid working status on {0}", e.RelativePath); Assert.IsFalse(e.Ignored); } else if (e.FullPath == dir) { Assert.AreEqual(GitStatus.None, e.WorkingDirectoryStatus); Assert.IsFalse(e.Ignored); } else if (Path.GetFileName(e.FullPath) == "F" || Path.GetFileName(e.FullPath) == "C") { // Empty directory Assert.AreEqual(GitStatus.Normal, e.WorkingDirectoryStatus, "Invalid status on {0}", e.RelativePath); Assert.AreEqual(GitStatus.None, e.IndexStatus, "Invalid status on {0}", e.RelativePath); Assert.IsTrue(e.Ignored); } else { Assert.AreEqual(GitStatus.None, e.IndexStatus, "Invalid status on {0}", e.RelativePath); Assert.AreEqual(GitStatus.None, e.WorkingDirectoryStatus, "Invalid status on {0}", e.RelativePath); Assert.IsFalse(e.Ignored); } n++; }); Assert.AreEqual(19, n); Assert.AreEqual(2, paths.Count); } foreach (string[] k in GreekTree()) { string p = Path.Combine(dir, k[0]); if (File.Exists(p)) { client.Stage(p); } } string A_dir = Path.Combine(dir, "A\\B"); { int n = 0; client.Status(A_dir, sa, delegate(object sender, GitStatusEventArgs e) { Assert.IsTrue(GitTools.IsNormalizedFullPath(e.FullPath)); Assert.IsTrue(e.FullPath.StartsWith(A_dir + "\\") || e.FullPath == A_dir); n++; }); Assert.AreEqual(5, n); } { var paths = new HashSet <string>(StringComparer.OrdinalIgnoreCase); int n = 0; foreach (string[] s in GreekTree()) { paths.Add(GitTools.GetNormalizedFullPath(Path.Combine(dir, s[0]))); } paths.Add(dir); n = 0; client.Status(dir, sa, delegate(object sender, GitStatusEventArgs e) { Assert.IsTrue(Path.IsPathRooted(e.FullPath)); Assert.IsTrue(paths.Remove(e.FullPath), "Can remove {0}", e.FullPath); if (e.NodeKind == GitNodeKind.File) { Assert.AreEqual(GitStatus.New, e.IndexStatus, "Invalid index status on {0}", e.RelativePath); Assert.AreEqual(GitStatus.Normal, e.WorkingDirectoryStatus, "Invalid working status on {0}", e.RelativePath); Assert.IsFalse(e.Ignored); } else if (e.FullPath == dir) { Assert.AreEqual(GitStatus.None, e.WorkingDirectoryStatus); Assert.IsFalse(e.Ignored); } else if (Path.GetFileName(e.FullPath) == "F" || Path.GetFileName(e.FullPath) == "C") { // Empty directory Assert.AreEqual(GitStatus.Normal, e.WorkingDirectoryStatus, "Invalid status on {0}", e.RelativePath); Assert.AreEqual(GitStatus.None, e.IndexStatus, "Invalid status on {0}", e.RelativePath); Assert.IsTrue(e.Ignored); } else { Assert.AreEqual(GitStatus.None, e.IndexStatus, "Invalid status on {0}", e.RelativePath); Assert.AreEqual(GitStatus.None, e.WorkingDirectoryStatus, "Invalid status on {0}", e.RelativePath); Assert.IsFalse(e.Ignored); } n++; }); Assert.AreEqual(19, n); Assert.AreEqual(2, paths.Count); } client.Commit(dir); { List <string> paths = new List <string>(); int n = 0; foreach (string[] s in GreekTree()) { paths.Add(GitTools.GetNormalizedFullPath(Path.Combine(dir, s[0]))); } paths.Add(dir); n = 0; client.Status(dir, sa, delegate(object sender, GitStatusEventArgs e) { Assert.IsTrue(GitTools.IsNormalizedFullPath(e.FullPath)); Assert.IsTrue(paths.Remove(e.FullPath), "Can remove {0}", e.FullPath); Assert.AreEqual(e.NodeKind, File.Exists(e.FullPath) ? GitNodeKind.File : GitNodeKind.Directory); Assert.IsFalse(e.IndexModified); Assert.IsFalse(e.WorkingDirectoryModified); n++; }); Assert.AreEqual(19, n); Assert.AreEqual(2, paths.Count); } } }
private static string getRemoteSourceBranch(string path, string sourceBranch) { IEnumerable <string> refs = GitTools.GetRemotePointsAt(path, sourceBranch); return(refs != null?refs.FirstOrDefault() : null); }