Skip to content

Commit

Permalink
Fix a rare error fetching the workitems associated to a changeset
Browse files Browse the repository at this point in the history
In certain cases of legacy TFS projects using Changeset::WorkItems could cause
a WorkItemTypeDeniedOrNotExistException (error TF201077) and cloning process
stopped. This change uses AssociatedWorkItems instead which works fine even
in this case.
  • Loading branch information
drolevar authored and siprbaum committed Oct 18, 2021
1 parent adb6382 commit d1c18c1
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 37 deletions.
1 change: 1 addition & 0 deletions doc/release-notes/NEXT.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
* Keep already committed files (e.g. `.gitignore`) when cloning with `--changeset` (#1382 by @boogisha)
* Correct WorkItem URL in the changeset metadata (#1396 by @siprbaum)
* Fix a rare error fetching the workitems associated to a changeset (#1395 @drolevar)
4 changes: 0 additions & 4 deletions src/GitTfs.Vs2015/TfsHelper.Vs2015.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ protected override string GetDialogAssemblyPath()
return string.Empty;
#endif
}
protected override bool HasWorkItems(Changeset changeset)
{
return Retry.Do(() => changeset.AssociatedWorkItems.Length > 0);
}

private string GetVsInstallDir()
{
Expand Down
33 changes: 5 additions & 28 deletions src/GitTfs.VsCommon/TfsHelper.Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -648,15 +648,12 @@ protected ITfsChangeset BuildTfsChangeset(Changeset changeset, IGitTfsRemote rem
var tfsChangeset = _container.With<ITfsHelper>(this).With<IChangeset>(_bridge.Wrap<WrapperForChangeset, Changeset>(changeset)).GetInstance<TfsChangeset>();
tfsChangeset.Summary = new TfsChangesetInfo { ChangesetId = changeset.ChangesetId, Remote = remote };

if (HasWorkItems(changeset))
tfsChangeset.Summary.Workitems = changeset.AssociatedWorkItems.Select(wi => new TfsWorkitem
{
tfsChangeset.Summary.Workitems = changeset.WorkItems.Select(wi => new TfsWorkitem
{
Id = wi.Id,
Title = wi.Title,
Url = HyperlinkService.GetWorkItemEditorUrl(wi.Id).ToString()
});
}
Id = wi.Id,
Title = wi.Title,
Url = HyperlinkService.GetWorkItemEditorUrl(wi.Id).ToString()
});
tfsChangeset.Summary.CheckinNotes = changeset.CheckinNote.Values.Select(note => new TfsCheckinNote
{
Name = note.Name,
Expand All @@ -667,26 +664,6 @@ protected ITfsChangeset BuildTfsChangeset(Changeset changeset, IGitTfsRemote rem
return tfsChangeset;
}

protected virtual bool HasWorkItems(Changeset changeset)
{
// This method wraps changeset.WorkItems, because
// changeset.WorkItems might result to ConnectionException: TF26175: Team Foundation Core Services attribute 'AttachmentServerUrl' not found.
// in this case assume that it is initialized to null
// NB: in VS2011 a new property appeared (AssociatedWorkItems), which works correctly
WorkItem[] result = null;
try
{
result = Retry.Do(() => changeset.WorkItems);
}
catch (ConnectionException exception)
{
if (!exception.Message.StartsWith("TF26175:"))
throw;
}

return result != null && result.Length > 0;
}

private readonly Dictionary<string, Workspace> _workspaces = new Dictionary<string, Workspace>();

public void WithWorkspace(string localDirectory, IGitTfsRemote remote, IEnumerable<Tuple<string, string>> mappings, TfsChangesetInfo versionToFetch, Action<ITfsWorkspace> action)
Expand Down
5 changes: 0 additions & 5 deletions src/GitTfs.VsCommon/TfsHelper.Vs2017Base.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,6 @@ private void LoadAssemblySearchPathFromVisualStudioPrivateRegistry(string devenv
myAssemblySearchPaths.Add(Path.Combine(myVisualStudioInstallationPath, myTeamExplorerFolder));
}

protected override bool HasWorkItems(Changeset changeset)
{
return Retry.Do(() => changeset.AssociatedWorkItems.Length > 0);
}

/// <summary>
/// Enumerates the list of installed VS instances and returns the first one
/// matching <see cref="MajorVersion"/>. Right now there is no way for the user to influence
Expand Down

0 comments on commit d1c18c1

Please sign in to comment.