Is it possible to compare files using Plastic SCM Command Line 'cm diff' function? - plasticscm

I'd like to compare two files at particular changesets to see if they are identical or not.
Something like:
>> cm diff rev:Folder\MyFile.py#cs:5 rev:Folder\MyFile.py#cs:10
<< True
I'm getting an error (can't find revision of file I specify) and I think I might not be using diff as it's intended. I've worked around my confusion by using getfile on the particular file and changesets I'm comparing and using a python library file compare.
Thanks.

The Plastic SCM default diff tool will open a GUI showing you the file differences.
But you can manually configure a different one (eg. diff.exe) manually editing the "/home/user/.plastic/client.conf" or using the Plastic SCM GUI:
<DiffToolData>
<FileType>enTextFile</FileType>
<FileExtensions>*</FileExtensions>
<Tools>
<string>diff.exe #sourcefile #destinationfile</string>
</Tools>
</DiffToolData>
This way, you can run diffs through the command line and based on the output, determine if the files are identical or not.

You can use cm patch command
reference : https://blog.plasticscm.com/2018/11/unified-diff-of-branch.html

Related

Where to get list of known repositories like #bazel_tools, #rules_jvm_external etc?

Sometimes I see extensions loading from the internet or built-in ones.
Canonical example:
load("#bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
However, I cannot distinguish local repo and known repo by looking at the load expression.
How can I check the source (location) of any repo which I see in my WORKSPACE/BUILD files?
If the Bazel label is sufficient as a source, you might try fetching repo roots with BUILD files with bazel query 'buildfiles(//...)'.
Otherwise, you could run bazel clean --expunge and run a build with --experimental_execution_log_file=<FILENAME>. This creates a protobuf based log of the actions by Bazel. In there, all internet repos are downloaded anew because of clean --expunge.
Check https://github.com/bazelbuild/bazel/tree/master/src/tools/execlog for a parser.
It is super inconvenient that this information is not available another way - afaik. I really hope someone swings by and corrects me, but this way you at least know the available sources you can correlate.
I'm new to Bazel, but as far as I understand:
Copy the name of the repo. E.g. io_bazel_rules_docker
Search it through the codebase
Look at how it's being loaded
E.g. if you see
http_archive(
name = "io_bazel_rules_docker",
...
)
http_file(
name = "io_bazel_rules_docker",
...
)
And you can conclude where it's coming from.
bazel query --output=build //external:repo_name works just fine.

How to start vNext TFS 2015 build revision at a specific number

I am using the vNext build system of TFS 2015.
I currently have the my builds versioning in the traditional format. Major.Minor-rev.RevisionNumber. So, if I have a build for Major 1, Minor 12, the build version would look like 1.12-rev.1 when I start. I would like to know if it is possible to have the build version start at a number other than one, say 55. Such that the build version would look like 1.12-rev.55, and then increment by one as usual after that.
Actually, it is possible to effect this in a vNext build without hacking the database.
There are 2 steps.
First, you will need to implement a powershell build step (as the first step of the build) with the following inline script:
#Set the BuildNumberOffset. (Change this to the difference between the TFS build number,
#and the number that your build needs.)
$BuildNumberOffset = 543
#Don't change
$BuildNumberParts = $($env:BUILD_BUILDNUMBER) -split '\.'
$TFSRevision = [int]$BuildNumberParts[$BuildNumberParts.Length-1]
$BuildNumberParts[$BuildNumberParts.Length-1] = ($TFSRevision + $BuildNumberOffset).ToString()
$BuildNumber = [string]::Join(".", $BuildNumberParts)
Write-Host "##vso[build.updatebuildnumber]$BuildNumber"
Second, on the Label format field of the repository tab set the label format to "$(Build.BuildNumber)" instead of "$(Build.DefinitionName)$(rev:.r)". This is important so that your label will be the same as your updated build number.
There is a way to do this. It isn't pretty, but it works.
Assuming you have a build number format of something like $(Major).$(Minor)-rev$(rev:.r)
To do this queue up a build which will get the number 1.12-rev.1. Then go to the TFS database and into a table called tbl_Build. Find that last build you did and change the value in the BuildNumberRevision column to 54.
The next build that fires off will now be 1.12-rev.55
Unfortunately, it's impossible.
Every build definition has a build number format field where you can use some macros to dictate what the resulting build number should look like. In this format we are using $(Rev:.rr) Its start by one.
What is $(Rev:.rr)?
To ensure that every completed build has a unique name. When a build
is completed, if nothing else in the build number has changed, the Rev
integer value is incremented by one.
Source:MSDN
Moreover, if you want to generating a custom build number without increment.
Here is a blog with detailed procedures:Generate custom build numbers in TFS Build vNext
Couldn't we just manually set this in the format for one build i.e:
$(Major).$(Minor)-rev$(rev:.54)
and then afterwards revert back to:
$(Major).$(Minor)-rev$(rev:.r)
Not tried it, but if it works it'll save hacking around in the database.
You can do this easily, but only if you are using a Git repository in conjunction with a tool called GitVersion
It is a wonderful tool that I always use with my git repos. For your use-case: When you have version 1.2.3 and you want to jump to version 1.2.55, you just add a git tag 'v1.2.55' and it will start the versioning from there. GitVersion is a lot more complicated and does a lot more, but that is one of the features. You don't have to mess with special PowerShell scripts or anything, it instead reads your git repo history and git tags overrides the calculated versioning. There is already a TFS/VSTS/Azure Devops extension called GitVersion that works great from the same developer.
The Answer of #Steve Sims works still with TFS 2017 vNext. Thanks a lot!
I had only to do the first step "to add the script as an inline powershell script in my build." Thanks to #PainElemental
With this "Build number format" in the Options-Tab it works:
$(BuildDefinitionName)_1.2.0$(rev:.r)
I didn't label my sources with the build, so I don't checked:
Second, on the Label format field of the repository tab set the label
format to "$(Build.BuildNumber)" instead of
"$(Build.DefinitionName)$(rev:.r)". This is important so that your
label will be the same as your updated build number.
I think, you can edit the Label Format on the "Advanced" GetSources Options. (usually hidden).
This was also very painful for us, migrating from a existing CI system with it's own build numbering, we needed build numbers to increment from a specific value. Hacking databases wasn't allowed in the organisation, offsets seemed a cludge.
In the end, we used an AutoIt script to start and stop builds and delete the build result using the WebUI and left it running. Not nice, but it did the job.
Needs tweaking for screen resolutions and such, timings also perhaps. Use AutoIt Window Info to find the button locations, make sure browser is fullscreen (not windowed) Run it for a few cycles to ensure it robust before setting the loop larger.
#include <AutoItConstants.au3>
;Increment TFS build count (Chrome browser buttons locations). Start from build result page.
For $i = 1 To 15 Step 1
ConsoleWrite ( "Loop " & $i & " of 5" & #CRLF )
Sleep(200)
MouseClick($MOUSE_CLICK_PRIMARY, 1800, 200, 2)
Sleep(500)
MouseClick($MOUSE_CLICK_PRIMARY, 1150, 881, 2)
Sleep(2000)
MouseClick($MOUSE_CLICK_PRIMARY, 1800, 200, 2)
Sleep(500)
MouseClick($MOUSE_CLICK_PRIMARY, 1055, 165, 2)
Sleep(10000)
Next
TFS/Devops is a really immature CI system, and it's not a patch on what we were running. Unfortunately corporate policy said we move to TFS, as nobody ever got fired for buying Microsoft products (but plenty of people should have got fired for buying them/forcing them where they don't belong).

TF checkin ignore "no files to check in" error

Background: I am writing a batch files to create and check in some contract files (language agnostic representations of API files) whenever we check into an API project. I am checking in the files with the following command:
tf checkin /flags myContractFiles
Frequently the contract files do not change so I often get this error:
There are no remaining changes to check in.
As a result the build fails.
Question: Is there a way to avoid this particular error?
What I have tried: I am aware of the /force flag for tf checkin (as suggested here), but would rather not use it because I would prefer to only check in when there actually is a change (I do not want to pollute the branch history with changesets with no changes). I have also seen the tf diff and tf folderdiff commands, but it looks like they output their result to the command line, and I am unable to do something like this:
if tf folderdiff ... (
tf checkin ...
)
You will either have to parse the folderdiff result to do what you want or create a custom activity to detect the changes through the API.

Equivalent to git difftool -y with libgit2sharp?

I am planning to replace the usage of git.exe from windows path by libgit2sharp for my plugin GitDiffMargin, A Visual Studio 2012 extension to display Git Diff on the margin of the current file. - https://github.com/laurentkempe/GitDiffMargin
I would like to know if there is an equivalent in libgit2sharp to start the external difftool using git difftool -y filename ?
I don't think it should be the responsibility of LibGit2Sharp to launch an external process. LibGit2Sharp goal is to provide a way to manipulate a git repository easily.
It means you can use it to:
Get the diff between files in the workdir and the previous version (in the index). To do that you can use the Repository.Diff.Compare(IEnumerable<string> paths, bool includeUntracked, ExplicitPathsOptions explicitPathsOptions) overload, which returns a TreeChanges object. From there, you can get a TreeEntryChanges object through the indexer of the treeChanges, which corresponds to the changes of a given file (use the .Patch property to get the actual content of the patch).
Get the configured diff tool by using the Repository.Config namespace (e.g.: repo.Config.Get<string>("diff.tool").Value, although you should also check if the value returned by the Get() method is null in case no diff tool has been configured by the user). That way, you can launch the diff tool by yourself.
Additional resources (v0.11.0):
Diff workdir to index tests
An example showing how to use the TreeChanges object
Configuration fixture, pretty self-explanatory
Note: it seems that at some point, you will need to know if a line has changed or not. I don't think there is an easy way to do that right now (apart from parsing the patch content manually). However, opening an issue on the LibGit2Sharp issue tracker might trigger some discussion around that (feel free to weigh in what kind of API you would like to have to do that!).
Edit: Before launching the external diff tool, you will need to copy the content of the file which is in the index in a temporary folder. You can lookup the blob of a file in the index by doing something like:
var indexEntry = repo.Index[fileName];
var blob = repo.Lookup(indexEntry.Id);
However... no filters are currently applied when you get the blob content, so the comparison is likely to produce false positives due to crlf differences.
There is currently an issue opened on libgit2 in order to propose an API to allow applying filters.

Can I create a selector file using the Plastic command line utility?

I am attempting to write a batch file for my developers to run that sets up workspaces. The batch file will use Plastic's command line utility, cm.exe.
When I create a workspace in the Plastic client GUI, there is a combo box that allows me to select the repository. This generates a plastic.workspace file, and a plastic.selector file that contains a reference to the selected repository.
However, when I use the command line utlity to make a workspace, I have to specify an existing selector:
cm mkwk MyWorkspace c:\MyWorkspacePath --selector=my.selector
or edit the selector when prompted:
cm mkwk MyWorkspace c:\MyWorkspacePath --selector
Ideally, I would like to be able to do something like
cm mkwk MyWorkspace c:\MyWorkspacePath MyRepository#MyServer:8888
and have the files generated the same way that they are done by the GUI.
Is there a way to do this using cm.exe, or do I have to write all the selectors beforehand?
Although it's not documented, you can issue the "mkwk" command with the "--repository" parameter. For example:
cm mkwk code c:\code --repository=code#localhost:8087
Hope it helps!

Resources