Get Changeset Id(s) from Merge - tfs

In TFVC you can merge changesets from Branch A into Branch B. Is it possible to view which changesets - specifically which ids - from Branch A were merged into Branch B?

You can use the following script :
$tfsUrl = "http://{Server}:{Port}/{Organization}/{Collection}"
$destinationBranchPath = "$/..."
$sourceBranchPath = "$/..."
# Change top with count of changesets you want to check
$body = 'repositoryId=&searchCriteria={"itemPath":"'+ $destinationBranchPath+'","itemVersion":"T","top":50}'
#Get top X changesets under destinationBranchPath
$changeSets = (Invoke-RestMethod -Method post "$tfsUrl/{Project}/_api/_versioncontrol/history?__v=5" -Body $body -UseDefaultCredentials).results
#Run over all changesets and check if sourceBranchPath is part of merage soruce path
foreach($changeSet in $changeSets)
{
$IsMerged = (Invoke-RestMethod -Method Get "$tfsUrl/_apis/tfvc/changesets/$($changeSet.changeList.changesetId)/changes" -UseDefaultCredentials).value.mergeSources.serverItem -like "*$sourceBranchPath*"
if($IsMerged)
{
#Print results
Write-Output $changeSet.changeList
}
}

Using the tf.exe command line tool, the merges command can provide the merge history between two branches.
So, in my example, from the source control root folder on my local machine I can run the following command in the shell of my choice tf vc merges a b /recursive to get a list of which changesets from a were included in merges to b:
Changeset Merged in Changeset Author Date
--------- ------------------- -------------------------------- ----------
20096 20292 Joey Bloggs 30/04/2018
20102 20292 Joey Bloggs 30/04/2018
20103 20292 Joey Bloggs 30/04/2018
Where the first column contains the changeset from branch a and the second column the changeset that merged it into branch b.
In order to get this working I had to add the folder location of tf.exe to my PATH variable.

Just adding another solution for anyone that don't want to use commands, but it will be a bit more time consuming if you want to know more than one merge
On TFS history of the merged branch, you can right click a changeset and choose Track Changeset option and then select the origin branch + merged branch in the next screen
https://learn.microsoft.com/en-us/azure/devops/repos/tfvc/view-where-when-changesets-have-been-merged?view=azure-devops

Related

Bitbucket squash commits on a branch

I have a load of commits, on a bitbucket branch where I was experimenting on the code. I want to squash all those into just one commit, without squashing all the other commits.
Does this call for a rebase.
Bit confused on what a rebase is.
yep you will get a console to edit the commits: like this:
git rebase -i qa then press keyboard 'i' to edit
you will see like this:
pick etc1
pick etc2
pick etc2
replace the word pick with 'f' and press esc y :wq
pick etc1 //this commit will the one commit
**f** etc2
**f** etc2
and press this command
git push origin +head

Determine perforce changelist number after running p4.run("sync") in Jenkins SCM pipeline

On the Jenkins server, Perforce plugin (P4) is installed.
Within my Jenkins server job pipeline (implemented as shared library in groovy-lang), there is a pipeline stage to sync from perforce to the jenkins workspace as:
p4.run("sync")
I want to determine the changelist number of this operation. I need to use this changelist number in the later stages of the pipeline.
I am thinking to do as follows:
p4.run("sync")
changelist_number = p4.run("changes -m1 #have")
Will this work? Or give me a better solution. Also I am very unfamiliar about this topic. It would be nice if you can explain what all this means.
The changelist number (that is, the highest changelist number associated with any synced revision) is returned as part of the p4 sync output if you're running in tagged mode:
C:\Perforce\test\merge>p4 changes ...
Change 226 on 2020/11/12 by Samwise#Samwise-dvcs-1509687817 'foo'
Change 202 on 2020/10/28 by Samwise#Samwise-dvcs-1509687817 'Populate //stream/test.'
C:\Perforce\test\merge>p4 -Ztag sync ...
... depotFile //stream/test/merge/foo.txt
... clientFile c:\Perforce\test\merge\foo.txt
... rev 2
... action updated
... fileSize 20
... totalFileSize 20
... totalFileCount 1
... change 226
Tagged output is converted into a dictionary that's returned by the run method, so you should be able to just do:
changelist_number = p4.run("sync")[0]["change"]
to sync and get the changelist number as a single operation.
There are some edge cases here -- deleted files aren't synced and so the deleted revisions won't factor into that changelist number.
A more ironclad method is to put the horse before the cart -- get the current changelist number (from the depot, not limited to what's in your client), and then sync to that exact number. That way consistency is guaranteed; if a new changelist is submitted between the two commands, your stored changelist number still matches what you synced to.
changelist_number = p4.run("changes", "-m1", "-ssubmitted")[0]["change"]
p4.run("sync", "#{changelist_number}")
Any other client syncing to that changelist number is guaranteed to get the same set of revisions (subject to its View).

Get commits without review

I have a list of JIRA issues that have one or many commits:
J1 (c11, c12, ..., c1n)
J2 (c21, c22, ..., c2m)
...
Jk (ck1, ck2, ..., cky)
where n,m,y >= 1
Using Crucible I'm trying to create reviews for J1,..., Jk (or for c11, ..., cky - because it's ok if the number of Crucible reviews is bigger than the number of JIRA issues).
In order to achieve this, I want to see using EyeQL which are the commits without a created review (not necessarily closed).
If I run the following query:
select ...
from ...
where
...
and not reviewed
group by ...
return ...
it returns only the commits that don't have a "complete" review. But I want to see only the commits that don't have a "review" (regardless of its state).
How can I achieve this behavior?
I want something like and doesn't have any created review instead of and not reviewed.
Using the clause not in any review should work, i.e.:
select revisions from dir "/" where (not in any review) order by date desc group by changeset return path, revision, author, date, csid
See the EyeQL reference for the full grammar description with examples.

Searching for all TFS changesets based on a check-in Comment

Is there a way to search TFS using PowerShell to find all changesets that contain some sub-string in the check-in comment? I'd like to see the individual files in all the changesets in one view. In my case I am searching for all changesets that contain a defect number e.g. 'D-12345'.
I tried the example as outlined here. But running ...
tf history $/MyCodeRepo/Trunk -r /noprompt /format:detailed | ? { $_.comment -like *D-12345* }
... gives me several errors:
You must provide a value expression on the right-hand side of the
'-like' operator.
You must provide a value expression on the
right-hand side of the '*' operator.
Unexpected token 'D-12345*' in
expression or statement.
I then tried putting quotes around the search string but that just returned no results.
I have TFS power tools installed and I know you can use searchcs to search by Comment but you have to open each changeset individually.
Any ideas how I can do this?
Thanks,
Try with
tf history $/ -r | ? { $_.comment -like *D-12345* }
You can also try with fpt searchcs

How to get the list of ChangesetIDs in an iteration path from source control?

I want to get the list of changes (i.e. the ChangeSetID's) associated with an iteration path.
Is there a way we can get the list of them ?
As long as you link your changesets to your work items!
There is no direct relationship between a check-in and an iteration except where it is created. When your developers check-in they get the option to relate their check-in to one or more work items within the work item tracking system. so:
Iteration -> Work Item -> Changeset
So in order to retrieve your list of changesets associated with your iteration you:
User the API to query for all work items where [System.Iteration] Under "[project]\Release 1\Sprint 1"
Loop through each work item returned and return all changeset links
I hope this helps you...
Code paraphrased:
To get Work item Store
_store = collection.GetService<WorkItemStore>();
To get Query Results
_store.Query("SELECT [System.Id], [System.WorkItemType], [System.Title], [System.AssignedTo], [System.State] FROM WorkItems WHERE [System.TeamProject] = #project AND [System.IterationPath] UNDER 'TfsExtensions\TfsFieldAnnotate\Release 1' ORDER BY [System.Id] ")
Each work item then contains "wi.Links" and you should be able to find the Changeset Lin Type easily...

Resources