public bool Connect() { TeamProjectPicker tpp = new TeamProjectPicker(TeamProjectPickerMode.SingleProject, false); if (tpp.ShowDialog() == DialogResult.OK && tpp.SelectedProjects.Length > 0) { Tfs = tpp.SelectedTeamProjectCollection; ProjectInfo = tpp.SelectedProjects[0]; Vcs = Tfs.GetService <VersionControlServer>(); Css4 = Tfs.GetService <ICommonStructureService4>(); TestService = Tfs.GetService <ITestManagementService>(); TestProject = TestService.GetTeamProject(ProjectInfo.Name); WorkItemStore = Tfs.GetService <WorkItemStore>(); GSS = (IGroupSecurityService)Tfs.GetService(typeof(IGroupSecurityService)); BuildServer = (IBuildServer)Tfs.GetService(typeof(IBuildServer)); //TfsTeamService teamService = Tfs.GetService<TfsTeamService>(); //AllTeams = teamService.QueryTeams(ProjectInfo.Uri); CollectAllBugTransitions(); return(true); } else { return(false); } }
private IGitTfsRemote InitTfsRemoteOfChangeset(IBranchObject tfsBranch, int parentChangesetId, IRenameResult renameResult = null) { if (tfsBranch.IsRoot) { return(InitTfsBranch(this.remoteOptions, tfsBranch.Path)); } var branchesDatas = Tfs.GetRootChangesetForBranch(tfsBranch.Path, parentChangesetId); IGitTfsRemote remote = null; foreach (var branch in branchesDatas) { var rootChangesetId = branch.RootChangeset; remote = InitBranch(this.remoteOptions, tfsBranch.Path, rootChangesetId, true); if (remote == null) { stdout.WriteLine("warning: root commit not found corresponding to changeset " + rootChangesetId); stdout.WriteLine("=> continuing anyway by creating a branch without parent..."); return(InitTfsBranch(this.remoteOptions, tfsBranch.Path)); } if (branch.IsRenamedBranch) { remote.Fetch(renameResult: renameResult); } } return(remote); }
private IEnumerable <ITfsChangeset> FetchChangesets(bool byLots, int lastVersion = -1) { int lowerBoundChangesetId; // If we're starting at the Root side of a branch commit (e.g. C1), but there ar // invalid commits between C1 and the actual branch side of the commit operation // (e.g. a Folder with the branch name was created [C2] and then deleted [C3], // then the root-side was branched [C4; C1 --branch--> C4]), this will detecte // only the folder creation and deletion operations due to the lowerBound being // detected as the root-side of the commit +1 (C1+1=C2) instead of referencing // the branch-side of the branching operation [C4]. if (_properties.InitialChangeset.HasValue || firstChangesetId.HasValue) { var firstChangesetInBranch = Math.Max(_properties.InitialChangeset ?? int.MinValue, firstChangesetId ?? int.MinValue); lowerBoundChangesetId = Math.Max(MaxChangesetId + 1, firstChangesetInBranch); } else { lowerBoundChangesetId = MaxChangesetId + 1; } Trace.WriteLine(RemoteRef + ": Getting changesets from " + lowerBoundChangesetId + " to " + lastVersion + " ...", "info"); if (!IsSubtreeOwner) { return(Tfs.GetChangesets(TfsRepositoryPath, lowerBoundChangesetId, this, lastVersion, byLots)); } return(_globals.Repository.GetSubtrees(this) .SelectMany(x => Tfs.GetChangesets(x.TfsRepositoryPath, lowerBoundChangesetId, x, lastVersion, byLots)) .OrderBy(x => x.Summary.ChangesetId)); }
public TfsCache(TfsTeamProjectCollection tfs, string rootFolder, IThreadingServices threadingServices) { this.Tfs = tfs; this.VersionControlServer = Tfs.GetService <VersionControlServer>(); _folders = new TfsFolderCache(rootFolder, TimeSpan.FromSeconds(5), VersionControlServer, threadingServices); _files = new TfsFilesCache(rootFolder, TimeSpan.FromSeconds(30), VersionControlServer, threadingServices); }
private IGitTfsRemote InitTfsRemoteOfChangeset(IBranchObject tfsBranch, int parentChangesetId) { if (tfsBranch.IsRoot) { return(InitTfsBranch(this.remoteOptions, tfsBranch.Path)); } var branchesDatas = Tfs.GetRootChangesetForBranch(tfsBranch.Path, parentChangesetId); IGitTfsRemote remote = null; foreach (var branch in branchesDatas) { var rootChangesetId = branch.RootChangeset; remote = InitBranch(this.remoteOptions, tfsBranch.Path, rootChangesetId, true); if (remote == null) { stdout.WriteLine("error: root commit not found corresponding to changeset " + rootChangesetId); return(null); } if (branch.IsRenamedBranch) { remote.Fetch(); } } return(remote); }
private void WriteFilesForTfs(ProjectFile project, FileToWrite file) { Log("Processing file: " + file.Path); if (File.Exists(file.Path)) { var tfsFile = File.ReadAllText(file.Path); if (tfsFile.Equals(file.Contents)) { Log(tfsFile); Log(file.Contents); Log(file.Path + " was unchanged."); return; } file.TempFile = Path.Combine(file.Directory, "zzzTempEarlyBoundGenerator." + Path.GetFileName(file.Path) + ".tmp"); Log("Creating Temp File " + file.TempFile); File.WriteAllText(file.TempFile, file.Contents); file.HasChanged = true; } else { File.WriteAllText(file.Path, file.Contents); Tfs.Add(file.Path); Console.WriteLine(file.Path + " created."); project.AddFileIfMissing(file.Path); } }
public void Unshelve(string shelvesetOwner, string shelvesetName, string destinationBranch, Action <Exception> ignorableErrorHandler) { var destinationRef = GitRepository.ShortToLocalName(destinationBranch); if (Repository.HasRef(destinationRef)) { throw new GitTfsException("ERROR: Destination branch (" + destinationBranch + ") already exists!"); } var shelvesetChangeset = Tfs.GetShelvesetData(this, shelvesetOwner, shelvesetName); var parentId = shelvesetChangeset.BaseChangesetId; var ch = GetTfsChangesetById(parentId); if (ch == null) { throw new GitTfsException("ERROR: Parent changeset C" + parentId + " not found." + " Try fetching the latest changes from TFS"); } var log = Apply(ch.GitCommit, shelvesetChangeset, ignorableErrorHandler); var commit = Commit(log); Repository.UpdateRef(destinationRef, commit, "Shelveset " + shelvesetName + " from " + shelvesetOwner); }
public void RunFinished() { var projectFullName = Project.FullName; Dte.Solution.Remove(Project); var fInfoProject = new FileInfo(projectFullName); var dInfoProject = new DirectoryInfo(fInfoProject.DirectoryName ?? throw new InvalidOperationException()); var folder = dInfoProject.Parent?.FullName + "\\" + ProjectName; Utility.TryDeleteDirectory(folder); dInfoProject.MoveTo(folder); Dte.Solution.SaveAs(Dte.Solution.FullName); var tfs = new Tfs(Dte); tfs.Undo(fInfoProject.DirectoryName); Utility.TryDeleteDirectory(folder + "\\bin"); Utility.TryDeleteDirectory(folder + "\\obj"); Utility.TryDeleteFile(folder + "\\" + ProjectName + ".csproj"); Utility.TryDeleteFile(folder + "\\" + ProjectName + ".csproj.vspscc"); Utility.TryDeleteFile(folder + "\\" + ProjectName + ".csproj.user"); tfs.Add(dInfoProject.FullName); Dte.Solution.SaveAs(Dte.Solution.FullName); var fullName = Dte.Solution.FullName; Port = (Dte.Solution.Projects.Count + 1).ToString(); UpdateSolutionFile(fullName, ProjectName, NetVersion, Port); Dte.Solution.Open(fullName); }
public frmMerge(Tfs tfs) { _tfs = tfs; _tfs.CarregaMerges(); InitializeComponent(); gridMerges.DataSource = _tfs.Merges; }
private bool ProcessMergeChangeset(ITfsChangeset changeset, bool stopOnFailMergeCommit, ref string parentCommit) { var parentChangesetId = Tfs.FindMergeChangesetParent(TfsRepositoryPath, changeset.Summary.ChangesetId, this); var shaParent = Repository.FindCommitHashByChangesetId(parentChangesetId); if (shaParent == null) { shaParent = FindMergedRemoteAndFetch(parentChangesetId, stopOnFailMergeCommit); } if (shaParent != null) { parentCommit = shaParent; } else { if (stopOnFailMergeCommit) { return(false); } //TODO : Manage case where there is not yet a git commit for the parent changset!!!!! stdout.WriteLine("warning: this changeset " + changeset.Summary.ChangesetId + " is a merge changeset. But it can't have been managed accordingly because one of the parent changeset " + parentChangesetId + " is not present in the repository! If you want to do it, fetch the branch containing this changeset before retrying..."); } return(true); }
private int GetLatestChangesetId() { if (!string.IsNullOrEmpty(TfsRepositoryPath)) { return(Tfs.GetLatestChangesetId(this)); } return(globals.Repository.GetSubtrees(this).Select(x => Tfs.GetLatestChangesetId(x)).Max()); }
public long Checkin(string head, TfsChangesetInfo parentChangeset, CheckinOptions options) { var changeset = 0L; Tfs.WithWorkspace(WorkingDirectory, this, parentChangeset, workspace => changeset = Checkin(head, parentChangeset.GitCommit, workspace, options)); return(changeset); }
public long Checkin(string head, TfsChangesetInfo parentChangeset) { var changeset = 0L; Tfs.WithWorkspace(WorkingDirectory, this, parentChangeset, workspace => changeset = Checkin(head, parentChangeset, workspace)); return(changeset); }
private IGitTfsRemote FindOrInitTfsRemoteOfChangeset(int parentChangesetId, bool mergeChangeset, IRenameResult renameResult, out string omittedParentBranch) { omittedParentBranch = null; IGitTfsRemote tfsRemote; IChangeset parentChangeset = Tfs.GetChangeset(parentChangesetId); //I think you want something that uses GetPathInGitRepo and ShouldSkip. See TfsChangeset.Apply. //Don't know if there is a way to extract remote tfs repository path from changeset datas! Should be better!!! var remote = Repository.ReadAllTfsRemotes().FirstOrDefault(r => parentChangeset.Changes.Any(c => r.GetPathInGitRepo(c.Item.ServerItem) != null)); if (remote != null) { tfsRemote = remote; } else { // If the changeset has created multiple folders, the expected branch folder will not always be the first // so we scan all the changes of type folder to try to detect the first one which is a branch. // In most cases it will change nothing: the first folder is the good one IBranchObject tfsBranch = null; string tfsPath = null; var allBranches = Tfs.GetBranches(true); foreach (var change in parentChangeset.Changes) { tfsPath = change.Item.ServerItem; tfsPath = tfsPath.EndsWith("/") ? tfsPath : tfsPath + "/"; tfsBranch = allBranches.SingleOrDefault(b => tfsPath.StartsWith(b.Path.EndsWith("/") ? b.Path : b.Path + "/")); if (tfsBranch != null) { // we found a branch, we stop here break; } } if (mergeChangeset && tfsBranch != null && string.Equals(Repository.GetConfig(GitTfsConstants.IgnoreNotInitBranches), true.ToString(), StringComparison.InvariantCultureIgnoreCase)) { Trace.TraceInformation("warning: skip not initialized branch for path " + tfsBranch.Path); tfsRemote = null; omittedParentBranch = tfsBranch.Path + ";C" + parentChangesetId; } else if (tfsBranch == null) { Trace.TraceInformation("error: branch not found. Verify that all the folders have been converted to branches (or something else :().\n\tpath {0}", tfsPath); tfsRemote = null; omittedParentBranch = ";C" + parentChangesetId; } else { tfsRemote = InitTfsRemoteOfChangeset(tfsBranch, parentChangeset.ChangesetId, renameResult); if (tfsRemote == null) { omittedParentBranch = tfsBranch.Path + ";C" + parentChangesetId; } } } return(tfsRemote); }
public void EnsureTfsAuthenticated() { if (isTfsAuthenticated) { return; } Tfs.EnsureAuthenticated(); isTfsAuthenticated = true; }
private void GetDataFromTfs(int?lastId, int itemSize, bool isFullCall = false) { IEnumerable <TFSCore.IHistoryItem> historyItems; Debug.WriteLine($"Getting HistoryItems from TFS {lastId} {itemSize}"); historyItems = Tfs.GetHistory(TeamProject.ServerItem, lastId, itemSize); IList <TFSCore.IHistoryItem> modifiedHistoryItems = new List <IHistoryItem>(); foreach (HistoryItem historyItem in historyItems) { if (CancellationTokenSource.IsCancellationRequested) { return; } modifiedHistoryItems.Add(HistoryItems.AddOrUpdateWithoutNotification(historyItem, (item, item1) => item.ChangeSetId == item1.ChangeSetId, (items, index, newItem) => { // make sure we keep our "ExtendedProperties" IHistoryItem.CopyTo(items[index], newItem); })); } HistoryItems.NotifyReset(); Debug.WriteLine($"Got {historyItems.Count()} HistoryItems from TFS"); SaveDataToCache(true, false); Debug.WriteLine($"Resolving Workitems for {historyItems.Count()}"); foreach (HistoryItem historyItem in modifiedHistoryItems) { if (CancellationTokenSource.IsCancellationRequested) { return; } foreach (WorkItem workItem in historyItem.WorkItems) { if (CancellationTokenSource.IsCancellationRequested) { return; } Debug.WriteLine($"Resolved Workitems for {historyItem.ChangeSetId}"); workItem.UpdateIndexedWords(true); WorkItems.AddOrUpdate(workItem, (item, item1) => item.Id == item1.Id, (items, index, newItem) => items[index] = newItem); } // Updating Cache historyItem.UpdateIndexedWords(true); } SaveDataToCache(true, true); if (!isFullCall) { GetDataFromTfs(null, Int32.MaxValue, true); } }
private ITfsChangeset GetLatestChangeset() { if (!string.IsNullOrEmpty(TfsRepositoryPath)) { return(Tfs.GetLatestChangeset(this)); } var changesetId = globals.Repository.GetSubtrees(this).Select(x => Tfs.GetLatestChangeset(x)).Max(x => x.Summary.ChangesetId); return(GetChangeset(changesetId)); }
public void QuickFetch() { var changeset = Tfs.GetLatestChangeset(this); AssertTemporaryIndexEmpty(); var log = CopyTree(MaxCommitHash, changeset); UpdateRef(Commit(log), changeset.Summary.ChangesetId); DoGcIfNeeded(); }
private void PendChangesToWorkspace(string head, string parent, ITfsWorkspaceModifier workspace) { using (var tidyWorkspace = new DirectoryTidier(workspace, Tfs.GetLatestChangeset(this).GetFullTree())) { foreach (var change in Repository.GetChangedFiles(parent, head)) { change.Apply(tidyWorkspace); } } }
private void WithWorkspace(TfsChangesetInfo parentChangeset, Action <ITfsWorkspace> action) { // If there isn't a custom workspace, and a workspace is lingering from a previous // git-tfs run, clean it up. If the user is using a custom workspace dir, leave // it for them to explicitly clean up, in case they're doing something unsupported // with it. Tfs.CleanupWorkspaces(DefaultWorkingDirectory); Tfs.WithWorkspace(WorkingDirectory, this, parentChangeset, action); }
private string FindMergedRemoteAndFetch(int parentChangesetId, bool stopOnFailMergeCommit) { var tfsRemotes = FindTfsRemoteOfChangeset(Tfs.GetChangeset(parentChangesetId)); foreach (var tfsRemote in tfsRemotes.Where(r => string.Compare(r.TfsRepositoryPath, this.TfsRepositoryPath, StringComparison.InvariantCultureIgnoreCase) != 0)) { var fetchResult = tfsRemote.Fetch(stopOnFailMergeCommit); } return(Repository.FindCommitHashByChangesetId(parentChangesetId)); }
private IEnumerable <ITfsChangeset> FetchChangesets() { Trace.WriteLine(RemoteRef + ": Getting changesets from " + (MaxChangesetId + 1) + " to current ...", "info"); // TFS 2010 doesn't like when we ask for history past its last changeset. if (MaxChangesetId == Tfs.GetLatestChangeset(this).Summary.ChangesetId) { return(Enumerable.Empty <ITfsChangeset>()); } return(Tfs.GetChangesets(TfsRepositoryPath, MaxChangesetId + 1, this)); }
private void WriteFileIfDifferent(ProjectFile project, FileToWrite file) { Log("Processing file: " + file.Path); if (UseTfsToCheckoutFiles) { if (File.Exists(file.Path)) { Trace.TraceInformation(Path.GetFileName(file.Path) + " Checking out and updating if different."); var tempFile = Path.Combine(file.Directory, "zzzTempEarlyBoundGenerator." + Path.GetFileName(file.Path) + ".tmp"); try { Log("Creating Temp File " + tempFile); File.WriteAllText(tempFile, file.Contents); var hasChanged = Tfs.AreDifferent(file.Path, tempFile); if (hasChanged) { Console.WriteLine($"{file.Path} was changed. Checking Out from TFS."); Tfs.Checkout(file.Path); Log("Updating File locally"); File.Copy(tempFile, file.Path, true); } var message = file.Path + $" was {(hasChanged ? "" : "un")}changed."; if (file.IsMainFile) { Console.WriteLine(message); } else { Log(message); } } finally { File.Delete(tempFile); } } else { File.WriteAllText(file.Path, file.Contents); Tfs.Add(file.Path); Console.WriteLine(file.Path + " created."); project.AddFileIfMissing(file.Path); } return; } EnsureFileIsAccessible(file.Path); project.AddFileIfMissing(file.Path); Trace.TraceInformation(Path.GetFileName(file.Path) + " created / updated."); Log("Writing file: " + file.Path); File.WriteAllText(file.Path, file.Contents); Log("Completed file: " + file); }
/// <summary> /// Returns true if the file was unchanged and an undo operation was performed /// </summary> /// <param name="fileName"></param> /// <returns></returns> protected bool UndoCheckoutIfUnchanged(string fileName) { if (!UseTfsToCheckoutFiles) { return(false); } Log("Checking accessibility for file " + fileName); return(Tfs.UndoCheckoutIfUnchanged(fileName)); }
private IEnumerable <ITfsChangeset> FetchChangesets(bool byLots, long lastVersion = -1) { if (!IsSubtreeOwner) { return(Tfs.GetChangesets(TfsRepositoryPath, MaxChangesetId + 1, this, lastVersion, byLots)); } return(globals.Repository.GetSubtrees(this) .SelectMany(x => Tfs.GetChangesets(x.TfsRepositoryPath, this.MaxChangesetId + 1, x, lastVersion, byLots)) .OrderBy(x => x.Summary.ChangesetId)); }
public frmChangeSets() { InitializeComponent(); dataGridView1.AutoGenerateColumns = false; _tfs = new Tfs(); tbUsuario.Text = _tfs.Usuario; tbCollection.Text = _tfs.Collection; Workspaces(); tbBranchOrigem.Text = _tfs.BranchOrigem; tbBranchDestino.Text = _tfs.BranchDestino; tbCaminhoTfExe.Text = _tfs.CaminhoTfExe; }
public void Unshelve(string shelvesetOwner, string shelvesetName, string destinationBranch) { var destinationRef = "refs/heads/" + destinationBranch; if (Repository.HasRef(destinationRef)) { throw new GitTfsException("ERROR: Destination branch (" + destinationBranch + ") already exists!"); } var shelvesetChangeset = Tfs.GetShelvesetData(this, shelvesetOwner, shelvesetName); Apply(shelvesetChangeset, destinationRef); }
private bool ProcessMergeChangeset(ITfsChangeset changeset, bool stopOnFailMergeCommit, ref string parentCommit) { if (!Tfs.CanGetBranchInformation) { stdout.WriteLine("info: this changeset " + changeset.Summary.ChangesetId + " is a merge changeset. But was not treated as is because this version of TFS can't manage branches..."); } else if (!IsIgnoringBranches()) { var parentChangesetId = Tfs.FindMergeChangesetParent(TfsRepositoryPath, changeset.Summary.ChangesetId, this); if (parentChangesetId < 1) // Handle missing merge parent info { if (stopOnFailMergeCommit) { return(false); } stdout.WriteLine("warning: this changeset " + changeset.Summary.ChangesetId + " is a merge changeset. But git-tfs is unable to determine the parent changeset."); return(true); } var shaParent = Repository.FindCommitHashByChangesetId(parentChangesetId); if (shaParent == null) { string omittedParentBranch; shaParent = FindMergedRemoteAndFetch(parentChangesetId, stopOnFailMergeCommit, out omittedParentBranch); changeset.OmittedParentBranch = omittedParentBranch; } if (shaParent != null) { parentCommit = shaParent; } else { if (stopOnFailMergeCommit) { return(false); } stdout.WriteLine("warning: this changeset " + changeset.Summary.ChangesetId + " is a merge changeset. But git-tfs failed to find and fetch the parent changeset " + parentChangesetId + ". Parent changeset will be ignored..."); } } else { stdout.WriteLine("info: this changeset " + changeset.Summary.ChangesetId + " is a merge changeset. But was not treated as is because of your git setting..."); changeset.OmittedParentBranch = ";C" + changeset.Summary.ChangesetId; } return(true); }
private LogEntry CopyTree(string lastCommit, ITfsChangeset changeset) { LogEntry result = null; WithTemporaryIndex(() => Tfs.WithWorkspace(WorkingDirectory, this, changeset.Summary, workspace => { GitIndexInfo.Do(Repository, index => result = changeset.CopyTree(index, workspace)); result.Tree = Repository.CommandOneline("write-tree"); })); if (!String.IsNullOrEmpty(lastCommit)) { result.CommitParents.Add(lastCommit); } return(result); }
private void WithWorkspace(TfsChangesetInfo parentChangeset, Action <ITfsWorkspace> action) { //are there any subtrees? var subtrees = globals.Repository.GetSubtrees(this); if (subtrees.Any()) { Tfs.WithWorkspace(WorkingDirectory, this, subtrees.Select(x => new Tuple <string, string>(x.TfsRepositoryPath, x.Prefix)), parentChangeset, action); } else { Tfs.WithWorkspace(WorkingDirectory, this, parentChangeset, action); } }