Is there a function equivalent to git diff FILE in libgit2? In other words, how to efficiently retrieve the diff of a single file without having libgit2 to look at other files in the working directory?
git diff FILE will display the changes you've made relative to the index.
This can be achieved through the use of the libgit2 git_diff_index_to_workdir() function.
This function accepts a git_diff_options structure as a parameter into which you can provide a pathspec, or a list of pathspecs, you're specifically interested in.
More information about this:
Documentation of this function.
Unit test leveraging this use case.
Related
I have a footer that generates info about the diagram, like the date and user who created the image. I would like to include the git SHA. I need some sort of built-in function, probably a preprocessor function, that lets me envoke system commands. I'm thinking something like the %date() command, only where I pass in the command and arguments I want to be executed and I get back the text from it being run in the shell. Something like
%sys_call("git rev-parse --short=10 HEAD")
There are different ways you could achieve this but it would require a bit of scripting:
Solution 1/:
Pass the git sha through an environment variable and use
%getenv function to retrieve it from the plantuml file
see here: https://plantuml.com/en/preprocessing#291cabbe982ff775
Solution 2/:
Have a script that write the sha in a text file and include this file from your plantuml file:
https://plantuml.com/en/preprocessing#393335a6fd28a804
I am trying to convert a *.coverage files into XML and then use them and publish code coverage in Jenkins. However, the path to the coverage file always is different and contains Timestamp. Due to that when I call CodeCoverage.exe and I am trying to pass a pattern instead of the direct path and direct file name.
Basically everything works when I point directly to the file, but when the pattern is used, nothing is happening.
*This is working*
C:\CodeCoverage\CoverageTool\CodeCoverage.exe analyze -output:.\TestResults\coverage.xml ".\TestResults\coveragefiles\test.coverage
*This is not working*
C:\CodeCoverage\CoverageTool\CodeCoverage.exe analyze -output:.\TestResults\coverage.xml ".\TestResults\**\*.coverage
Now trying to make it working in cmd, but letter will put it to the groovy (Jenkinsfile) as a bat command.
Is it even possible in that way? Should I first find a string, make a string variable, and pass it to the codecoverage ? thanks in advance
I want to get list of files and directories affected by specific commit. I have no problem getting the commit itself but I rather don't know how to get affected files and directories.
Just to make it clear I need something like this:
file x - deleted
file y - added
file z - modified
Git is snapshot-based; each commit includes a full list of files and their state. Any notion of "affected" files needs another commit to compare it to. This is commonly done against its parents, which seems to be what you're asking about. You can figure out which files are different between two commits (or more exactly, their trees) by using the git_diff family of functions.
You can find an example of doing so in the examples listing for libgit2. There is also a more general annotated diff example. The second link also shows how to list individual files as well as their contents, if you need that. Check the reference for a a full listing of available function to work with diffs.
Note that this won't give you affected directorires by itself, as Git does not track directories, but only files.
You're looking for git diff.
The same function exists in libgit2, and the documentation for it is here.
If you're analyzing older commits, "git diff [commit1] [commitAfterCommit1]" will give you a list of changes that the second commit made from the first. You could prune this output to get yourself just the changed file names.
Is there an easy way to check in which file version the function has been modified in Clearcase? In my current environment I have file where the function is modified in some prior check-ins. On doing compare with previous version, it is not the one. So I have to go and compare with all previous check-ins to figure out in which version this has been modified. So is there an easy way to do it?
You can check the cleartool annotate function
The annotate command lists the contents of a version, annotating each line to indicate when, and in which version, the line was added. You can customize the annotations using the –fmt option, which is described in the fmt_ccase reference page.
By default, annotate writes its output to a file whose file-name extension is .ann.
You can find an example in this answer.
See also "How to use ClearCase annotate sub-command?".
I have a directory with files likes this:
inbox/
data.20130813T1921.json
data.20130818T0123.json
data.20130901T1342.json
I'm using Apache Camel 2.11 and on process start, I only want to process one file: the latest. The other files can actually be ignored. Alternatively, the older files can be deleted once a new file has been processed.
I'm configuring my component using the following, but it obviously doesn't do what I need:
file:inbox/?noop=true
noop does keep the last file, but also all other files. On startup, Camel processes all existing files, which is more than I need.
What is the best way to only process the latest file?
You can use the sorting and then sort by name, and possible need to reverse it so the latest is first / last. You can try it out to see which one you need. And then set maxMessagesPerPoll=1 to only pickup one file. And you need to set eagerMaxMessagesPerPoll=false to allow to sort before limiting the number of files.
You can find details at: http://camel.apache.org/file2. See the section Sorting using sortBy for the sorting.
An alternative would be to still using the sorting to ensure the latest file is last. Then you can use the aggregator EIP to aggregate all the files, and use org.apache.camel.processor.aggregate.UseLatestAggregationStrategy as the aggregation strategy to only keep the last (which would be the latest file). Then you can instruct the file endpoint to delete=true to delete the files when done. You would then also need to configure the aggregator to completionFromBatchConsumer=true.
The aggregator eip is documented here: http://camel.apache.org/aggregator2