{"id":1233,"date":"2009-01-26T15:22:56","date_gmt":"2009-01-26T15:22:56","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/buckh\/2009\/01\/26\/how-to-determine-the-latest-changeset-in-your-workspace\/"},"modified":"2009-01-26T15:22:56","modified_gmt":"2009-01-26T15:22:56","slug":"how-to-determine-the-latest-changeset-in-your-workspace","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/buckh\/how-to-determine-the-latest-changeset-in-your-workspace\/","title":{"rendered":"How to determine the latest changeset in your workspace"},"content":{"rendered":"<p>[UPDATE 7\/25\/14] Added equivalent API calls.<\/p>\n<p>When you run get for your entire workspace without any argument, you are requesting that the server give you the latest set of files.&nbsp; Later you might wonder what changeset was used in that get.&nbsp; To figure that out, you can use the following <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/yxtbh4yh.aspx\">history command<\/a> from the root (top) of your workspace.<\/p>\n<blockquote>\n<p>tf history . \/r \/noprompt \/stopafter:1 \/version:W<\/p>\n<\/blockquote>\n<p>Here&#8217;s what that command means.&nbsp; The &#8220;. \/r&#8221; part says to look at the current directory recursively, which is why you must run it from the root (top directory) of your workspace.&nbsp; Here I&#8217;ve specified &#8220;\/noprompt&#8221; so that I don&#8217;t get dialog, but that&#8217;s optional.&nbsp; The &#8220;\/stopafter:1&#8221; option tells tf to print only one changeset.<\/p>\n<p>The version option is the part that tells the history command to consider history only up to what you have in your workspace.&nbsp; The &#8220;W&#8221; means workspace, and without the workspace name and owner being specified it means the current workspace.&nbsp; The version option could also be written as &#8220;\/version:1~W&#8221; to explicitly state that you are interested in history only up to what is in your workspace.&nbsp; The &#8220;1~&#8221; is implicit when it is not specified.&nbsp; Changeset 1 is when the root of the repository ($\/) was created.<\/p>\n<p>Since the history command sorts the changesets from highest to lowest, the result is that the command displays the highest changeset version of all files currently in your workspace.<\/p>\n<p>Here\u2019s the code to do the equivalent using the Version Control client API.<\/p>\n<pre class=\"code\"><span style=\"background: white;color: green\"> \/\/ The workspace info for the provided path\n <\/span><span style=\"background: white;color: #2b91af\">WorkspaceInfo <\/span><span style=\"background: white;color: black\">wsInfo = <\/span><span style=\"background: white;color: #2b91af\">Workstation<\/span><span style=\"background: white;color: black\">.Current.GetLocalWorkspaceInfo(filePath);\n\n <\/span><span style=\"background: white;color: green\">\/\/ Get the TeamProjectCollection and VersionControl server associated with the\n \/\/ WorkspaceInfo\n <\/span><span style=\"background: white;color: #2b91af\">TfsTeamProjectCollection <\/span><span style=\"background: white;color: black\">tpc = <\/span><span style=\"background: white;color: blue\">new <\/span><span style=\"background: white;color: #2b91af\">TfsTeamProjectCollection<\/span><span style=\"background: white;color: black\">(wsInfo.ServerUri);\n <\/span><span style=\"background: white;color: #2b91af\">VersionControlServer <\/span><span style=\"background: white;color: black\">vcServer = tpc.GetService&lt;<\/span><span style=\"background: white;color: #2b91af\">VersionControlServer<\/span><span style=\"background: white;color: black\">&gt;();\n\n <\/span><span style=\"background: white;color: green\">\/\/ Now get the actual Workspace OM object\n <\/span><span style=\"background: white;color: #2b91af\">Workspace <\/span><span style=\"background: white;color: black\">ws = vcServer.GetWorkspace(wsInfo);\n\n <\/span><span style=\"background: white;color: green\">\/\/ We are interested in the current version of the workspace\n <\/span><span style=\"background: white;color: #2b91af\">VersionSpec <\/span><span style=\"background: white;color: black\">versionSpec = <\/span><span style=\"background: white;color: blue\">new <\/span><span style=\"background: white;color: #2b91af\">WorkspaceVersionSpec<\/span><span style=\"background: white;color: black\">(ws);\n\n <\/span><span style=\"background: white;color: #2b91af\">QueryHistoryParameters <\/span><span style=\"background: white;color: black\">historyParams = <\/span><span style=\"background: white;color: blue\">new <\/span><span style=\"background: white;color: #2b91af\">QueryHistoryParameters<\/span><span style=\"background: white;color: black\">(filePath, <\/span><span style=\"background: white;color: #2b91af\">RecursionType<\/span><span style=\"background: white;color: black\">.Full);\n historyParams.ItemVersion = versionSpec;\n historyParams.VersionEnd = versionSpec;\n historyParams.MaxResults = 1;\n\n <\/span><span style=\"background: white;color: #2b91af\">Changeset <\/span><span style=\"background: white;color: black\">changeset = vcServer.QueryHistory(historyParams).FirstOrDefault();\n<\/pre>\n<p><\/span><\/p>\n<div id=\"scid:0767317B-992E-4b12-91E0-4F059A8CECA8:ec5210e6-59cb-42be-b3bb-40511197ff1a\" class=\"wlWriterSmartContent\" style=\"float: none;padding-bottom: 0px;padding-top: 0px;padding-left: 0px;margin: 0px;padding-right: 0px\">Technorati Tags: <a href=\"http:\/\/technorati.com\/tags\/team+foundation+server\" rel=\"tag\">team foundation server<\/a>,<a href=\"http:\/\/technorati.com\/tags\/source+control\" rel=\"tag\">source control<\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>[UPDATE 7\/25\/14] Added equivalent API calls. When you run get for your entire workspace without any argument, you are requesting that the server give you the latest set of files.&nbsp; Later you might wonder what changeset was used in that get.&nbsp; To figure that out, you can use the following history command from the root [&hellip;]<\/p>\n","protected":false},"author":94,"featured_media":10268,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[6,8],"class_list":["post-1233","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-source-control","tag-team-foundation"],"acf":[],"blog_post_summary":"<p>[UPDATE 7\/25\/14] Added equivalent API calls. When you run get for your entire workspace without any argument, you are requesting that the server give you the latest set of files.&nbsp; Later you might wonder what changeset was used in that get.&nbsp; To figure that out, you can use the following history command from the root [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/posts\/1233","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/users\/94"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/comments?post=1233"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/posts\/1233\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/media\/10268"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/media?parent=1233"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/categories?post=1233"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/tags?post=1233"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}