public void GetCommitChangesModifications() { var commit = "c6798c34577"; var changedFiles = new [] { "EditActions.cs", "SourceEditorView.cs", "SourceEditorWidget.cs", "DeleteActions.cs", "DocumentUpdateRequest.cs", "FoldMarkerMargin.cs", "HeightTree.cs", "LineSplitter.cs", "TextDocument.cs", "TextEditor.cs", "TextViewMargin.cs", }; var c = repo.Lookup <Commit> (commit); var changes = GitUtil.CompareCommits(repo, c.Parents.First(), c).ToArray(); Assert.AreEqual(11, changes.Length, "#1"); foreach (var file in changedFiles) { Assert.IsTrue(changes.Any(f => f.Path.EndsWith(".cs", StringComparison.Ordinal)), "#2." + file); } }
protected override bool Execute(IIntegrationResult result) { string repository = result.GetSourceData("$TqGitCI_repository"); string gitDirectory = result.GetSourceData("$TqGitCI_gitDirectory"); string branch = result.GetSourceData("$TqGitCI_branch"); string startBranch = result.GetSourceData("$TqGitCI_startBranch"); string projectName = result.GetSourceData("$TqGitCI_projectName"); string gitUserId = result.GetParameters("$TqGitCI_gitUserId"); string gitUserPassword = result.GetParameters("$TqGitCI_gitUserPassword"); git = new GitUtil(projectName, gitDirectory, repository, gitUserId, gitUserPassword); // Branch git.Checkout(result, branch); var diffBranchAndStartBranch = git.GetDiffList(result, startBranch); if (diffBranchAndStartBranch.Count > 0) { var mergeResult = git.Merge(result, startBranch); result.SetSourceData("$TqGitCI_mergeResult", mergeResult.Status.ToString()); result.SetParameters("$TqGitCI_mergeResult", mergeResult.Status.ToString()); if (mergeResult.Status == MergeStatus.Conflicts) { var conflictsList = git.GetConflictsList(result); result.SetSourceData("$TqGitCI_mergeExceptionMessage", $"{projectName} Conflicts({conflictsList.Count}) {branch} <- {startBranch}"); result.SetParameters("$TqGitCI_mergeExceptionMessage", $"{projectName} Conflicts({conflictsList.Count}) {branch} <- {startBranch}"); return(false); } } return(true); }
protected override bool CanShowOverlay(string path, FILE_ATTRIBUTE attributes) { try { if (ApplicationUtil.ProcessName != "explorer") { return(false); } //把优先级最高的结果缓存 低优先级直接读缓存 //if (_notGitList.Contains(path)) // return false; //LogUtil.Log("{0}: Process is getting the show state of {1}", Status, path); if (Status == FirstAccessStatus) { _statusMap[path] = GitUtil.GetStatus(path); } //_notGitList.Add(path);空文件夹检出项目时会混乱 虽然降效率了 没有太好的办法 //LogUtil.Log("{0}: Process has got the show state of {1}", Status, path); return(Status == _statusMap[path]); } catch (Exception ex) { ex.HelpLink = Status + " " + path; LogUtil.Log(ex); return(false); } }
public static GitFileSystem GetFileSystem(string repoUrl, string commitIdOrRefName) { Module.CheckInitalized(); if (commitIdOrRefName._IsEmpty()) { commitIdOrRefName = "refs/remotes/origin/master"; } string commitId; if (GitUtil.IsCommitId(commitIdOrRefName)) { commitId = commitIdOrRefName; } else { GitRepository repository = GetRepository(repoUrl); GitRef? reference = repository.EnumRef().Where(x => x.Name._IsSamei(commitIdOrRefName)).SingleOrDefault(); if (reference == null) { throw new ArgumentException($"The reference name \"{commitIdOrRefName}\" not found."); } commitId = reference.CommitId; } return(FileSystemSingleton[$"{repoUrl}@{commitId}"]); }
private static BuildInputHandler HandleGitInput(IPipelineRunManager pipelineRunManager, GitBuildInput git) => async cancellationToken => { var dir = pipelineRunManager.NextInputPath(); Directory.CreateDirectory(dir); await GitUtil.CloneRepo(git.Url, dir, git.Branch); return(dir); };
public void GetCommitChangesFullHistory() { Commit initial = null; Commit second = commits [commits.Length - 1].Commit; var changes = GitUtil.CompareCommits(repo, initial, second).ToArray(); Assert.AreEqual(4, changes.Length); Assert.That(changes.Select(x => x.Status), Is.All.EqualTo(ChangeKind.Added)); }
public void GetCommitChangesAddedRemoved() { var commit = "9ed729ee"; var changes = GitUtil.CompareCommits(repo, repo.Resolve(commit), repo.Resolve(commit + "^")).ToArray(); var add = changes.First(c => c.GetNewPath().EndsWith("DocumentLine.cs", StringComparison.Ordinal)); var remove = changes.First(c => c.GetOldPath().EndsWith("LineSegment.cs", StringComparison.Ordinal)); Assert.AreEqual(NGit.Diff.DiffEntry.ChangeType.ADD, add.GetChangeType(), "#1"); Assert.AreEqual("/dev/null", add.GetOldPath(), "#2"); Assert.AreEqual(NGit.Diff.DiffEntry.ChangeType.DELETE, remove.GetChangeType(), "#3"); Assert.AreEqual("/dev/null", remove.GetNewPath(), "#4"); }
public void GetCommitChangesAddedRemoved() { var commit = "9ed729ee"; var com = repo.Lookup <Commit> (commit); var changes = GitUtil.CompareCommits(repo, com.Parents.First(), com).ToArray(); var add = changes.First(c => c.Path.EndsWith("DocumentLine.cs", StringComparison.Ordinal)); var remove = changes.First(c => c.OldPath.EndsWith("LineSegment.cs", StringComparison.Ordinal)); Assert.AreEqual(ChangeKind.Renamed, add.Status, "#1"); Assert.AreEqual("main/src/core/Mono.Texteditor/Mono.TextEditor/Document/LineSegment.cs".Replace('/', Path.DirectorySeparatorChar), add.OldPath, "#2"); Assert.AreEqual(ChangeKind.Renamed, remove.Status, "#3"); Assert.AreEqual("main/src/core/Mono.Texteditor/Mono.TextEditor/Document/DocumentLine.cs".Replace('/', Path.DirectorySeparatorChar), remove.Path, "#4"); }
public void GetCommitChangesIgnoresUnchangedFiles() { var initial = commits [0]; var second = commits [1]; var changes = GitUtil.CompareCommits(repo, initial.Commit, second.Commit).ToArray(); Assert.AreEqual(3, changes.Length); var changeForB = changes.Single(x => x.Path == "b.cs"); var changeForC = changes.Single(x => x.Path == "c.cs"); Assert.AreEqual(ChangeKind.Modified, changeForB.Status); Assert.AreEqual(ChangeKind.Added, changeForC.Status); }
private void InitProcessData(IIntegrationResult result) { result.AddMessage("#InitProcessData"); projectName = GetGitRepositoryName(); gitDirectory = result.BaseFromWorkingDirectory(projectName); var builder = new UriBuilder(GitRepository); builder.UserName = string.Empty; builder.Password = string.Empty; gitUrl = builder.Uri.ToString(); git = new GitUtil(projectName, gitDirectory, gitUrl, GitUserId, GitUserPassword); isFirstRun = false; }
private async Task <string> HandleGitRepo(CancellationToken cancellationToken) { var config = Config; var repoDir = Path.Combine(ProjectDir, "repo"); if (!PathUtil.IsValidSubPath(config.Path)) { throw new Exception("Invalid project path."); } if (Directory.Exists(repoDir)) { Directory.Delete(repoDir, recursive: true); } await GitUtil.CloneRepo(config.Url, repoDir, config.Branch, depth : 1); return(await File.ReadAllTextAsync(Path.Combine(repoDir, config.Path), Encoding.UTF8, cancellationToken)); }
public void BlameWithRename() { LibGit2Sharp.Commands.Move(repo, "a.cs", "d.cs"); repo.Commit("Remove commit", signature, signature); var dData = commits [commits.Length - 1].Datas.Single(x => x.File == "a.cs"); var commit = repo.Head.Tip; var blame = GetBlameForFile(commit.Sha, "d.cs"); AssertBlame(dData, blame); // Also assert the changekind var changes = GitUtil.CompareCommits(repo, commit.Parents.Single(), commit).ToArray(); Assert.AreEqual(1, changes.Length); Assert.AreEqual(ChangeKind.Renamed, changes [0].Status); Assert.AreEqual("a.cs", changes [0].OldPath); Assert.AreEqual("d.cs", changes [0].Path); }
static void Git_Test_Clone() { GitUtil.Clone(GitTestBaseDir, GitUrl); }
public static void StartRepository(string repoUrl) { Module.CheckInitalized(); lock (RepositoryUpdateLock) { if (repoUrl.IndexOf("@") != -1) { throw new ArgumentException($"The repository name \'{repoUrl}\' must not contain '@'."); } if (Data.IsReadOnly) { throw new ApplicationException("Data.IsReadOnly"); } lock (Data.DataLock) { GitGlobalFsRepository?repoData = Data.ManagedData.RepositoryList.Where(x => x.Url._IsSamei(repoUrl)).SingleOrDefault(); L_RETRY: if (repoData == null) { string dirName = GenerateNewRepositoryDirName(repoUrl); string dirFullPath = Lfs.PathParser.Combine(RepoDir, dirName); Con.WriteDebug($"Clone the repository \"{repoUrl}\" to \"{dirFullPath}\" ..."); try { GitUtil.Clone(dirFullPath, repoUrl); } catch (Exception ex) { Con.WriteError($"GitUtil.Clone error: {ex.ToString()}"); throw; } Con.WriteDebug("Done."); GitRepository gitRepo = new GitRepository(dirFullPath); repoData = new GitGlobalFsRepository() { Url = repoUrl, LocalWorkDir = dirName, Repository = gitRepo, }; Data.ManagedData.RepositoryList.Add(repoData); } else { repoData.Url = repoUrl; if (repoData.Repository == null) { string dirName = repoData.LocalWorkDir._NullCheck(); string dirFullPath = Lfs.PathParser.Combine(RepoDir, dirName); try { GitRepository gitRepo = new GitRepository(dirFullPath); repoData.Repository = gitRepo; } catch (Exception ex) { Con.WriteDebug($"Repository local dir \"{dirFullPath}\" load error: {ex.ToString()}"); Con.WriteDebug($"Trying to clone as a new local dir."); Data.ManagedData.RepositoryList.Remove(repoData); Data.SyncWithStorage(HiveSyncFlags.SaveToFile, false); repoData = null; goto L_RETRY; } } } } Data.SyncWithStorage(HiveSyncFlags.SaveToFile, false); StartUpdateLoop(); } }