/// <summary> /// Apply the specified changes to the TFS workspace. This won't commit the changes. /// </summary> private bool ApplyGitChangeToWorkspace(TreeChanges treeChanges) { Debug.Assert(treeChanges.Any()); Debug.Assert(!HasPendingChangesBesidesLock()); return(_commitPortUtil.ApplyGitChangeToWorkspace(treeChanges)); }
private static void ThrowIfNonSupportedChangeTypes(TreeChanges changes) { if (changes.Any(c => c.Status == ChangeKind.Conflicted)) { throw new NotSupportedException("Conflicting changes is not yet supported."); } if (changes.Any(c => c.Status == ChangeKind.Copied)) { throw new NotSupportedException("Copied changes is not yet supported."); } if (changes.Any(c => c.Status == ChangeKind.Renamed)) { throw new NotSupportedException("Renamed changes is not yet supported."); } if (changes.Any(c => c.Status == ChangeKind.TypeChanged)) { throw new NotSupportedException("TypeChanged changes is not yet supported."); } }
private static bool HasVersionChange( TreeChanges diff, Commit commit, VersionContext context) { if (diff.Any(d => d.Path == Constants.VersionFileName)) { var commitConfig = GetConfiguration(commit, context); return(commitConfig != null && !_comparer.Equals(context.Configuration, commitConfig)); } return(false); }
private bool HasVersionChange( TreeChanges diff, Commit commit, IVersionContext context) { if (diff.Any(d => d.Path == Constants.ConfigurationFileName)) { var configAtCommit = GetCommitConfiguration(commit); if (configAtCommit == null) { return(false); } var branchConfigAtCommit = GetBranchConfiguration(configAtCommit, context.Result.CanonicalBranchName); return(!_comparer.Equals(context.Configuration, branchConfigAtCommit)); } return(false); }
public void RenameThresholdsAreObeyed() { SelfCleaningDirectory scd = BuildSelfCleaningDirectory(); var path = Repository.Init(scd.DirectoryPath); using (var repo = new Repository(path)) { const string originalPath = "original.txt"; const string renamedPath = "renamed.txt"; // 4 lines Touch(repo.Info.WorkingDirectory, originalPath, "a\nb\nc\nd\n"); repo.Index.Stage(originalPath); Commit old = repo.Commit("Initial", Constants.Signature, Constants.Signature); // 8 lines, 50% are from original file Touch(repo.Info.WorkingDirectory, originalPath, "a\nb\nc\nd\ne\nf\ng\nh\n"); repo.Index.Stage(originalPath); repo.Index.Move(originalPath, renamedPath); Commit @new = repo.Commit("Updated", Constants.Signature, Constants.Signature); var compareOptions = new CompareOptions { Similarity = new SimilarityOptions { RenameDetectionMode = RenameDetectionMode.Renames, }, }; compareOptions.Similarity.RenameThreshold = 30; TreeChanges changes = repo.Diff.Compare <TreeChanges>(old.Tree, @new.Tree, compareOptions: compareOptions); Assert.True(changes.All(x => x.Status == ChangeKind.Renamed)); compareOptions.Similarity.RenameThreshold = 90; changes = repo.Diff.Compare <TreeChanges>(old.Tree, @new.Tree, compareOptions: compareOptions); Assert.False(changes.Any(x => x.Status == ChangeKind.Renamed)); } }
/// <summary> /// Apply the specified changes to the TFS workspace. This won't commit the changes. /// </summary> public bool ApplyGitChangeToWorkspace(TreeChanges treeChanges) { Debug.Assert(treeChanges.Any()); foreach (var changeEntry in treeChanges) { var tfsFilePath = GetTfsWorkspacePath(changeEntry.Path); var tfsFileName = Path.GetFileName(tfsFilePath); switch (changeEntry.Status) { case ChangeKind.Added: if (File.Exists(tfsFilePath)) { _host.Error("Pending add found existing file {0}", tfsFileName); ApplyModified(changeEntry, tfsFilePath, tfsFileName); } else { _host.Verbose("Pending add {0}", tfsFileName); WriteObjectToFile(tfsFilePath, changeEntry.Oid, changeEntry.Path); _workspace.PendAdd(tfsFilePath); } break; case ChangeKind.Deleted: _host.Verbose("Pending delete {0}", tfsFileName); _workspace.PendDelete(tfsFilePath); break; case ChangeKind.Renamed: _workspace.PendRename(GetTfsWorkspacePath(changeEntry.OldPath), tfsFilePath); if (changeEntry.OldOid != changeEntry.Oid) { _workspace.PendEdit(tfsFilePath); CopyObjectToFile(tfsFilePath, changeEntry.Oid, changeEntry.Path); } // If there is a path case difference between TFS and Git then it will keep showing // up as a rename until an explicit path change occurs in TFS. Don't report such // differences as pends because it just causes noise to the output. if (!StringComparer.OrdinalIgnoreCase.Equals(changeEntry.OldPath, changeEntry.Path)) { _host.Verbose("Pending rename {0}", tfsFileName); } break; case ChangeKind.Modified: Debug.Assert(changeEntry.Oid != changeEntry.OldOid || changeEntry.OldMode != changeEntry.Mode); ApplyModified(changeEntry, tfsFilePath, tfsFileName); break; default: _host.Error("Unknown change status {0} {1}", changeEntry.Status, changeEntry.Path); return(false); } } return(true); }