I am trying to write a jgit code to find all associated branches(Refs) based on a commit. The Idea is basically to call nameRev with addPrefix and pass head, remote and tag as params to find all branches.
Iterable<RevCommit> commits = repositoryBrowser.getLatestGitCommits(4);
for (RevCommit commit : commits) {
Map<ObjectId, String> branch= new Git(repository).nameRev().add(commit.toObjectId()).call();
log(commit.getShortMessage() + "\tbranch: " + ss);
}
Output of the above is as under:
Release 2.3.2 from xxxxxxx branch: {AnyObjectId[3533e4063644c0436ac5e873a75b647703aea6dd]=v2.3.2}
The problem is that for the first commit, branch points to a tag (refs/tags/v2.3.2). It is hard to imagine a commit which does not belongs to any branch and just to a tag.
I am a bit confused, is my approach right or am I doing something wrong here. Any help would be appreciated.
Related
Consider the following code:
mt.resolve().getQualifiedSignature();
Here mt is of type MethodDeclaration, and it might come from a MethodCallExpr.
Now in order it to work accurately, I need to set the following:
CombinedTypeSolver combinedTypeSolver = new CombinedTypeSolver();
combinedTypeSolver.add(new ReflectionTypeSolver());
combinedTypeSolver.add(new JavaParserTypeSolver(new File("src/java1/")));
combinedTypeSolver.add(new JavaParserTypeSolver(new File("src/java2/
")));
This is easy, except I have two issues considering my scenario.
1) I can not set the root source directories manually. I need to find them automatically.
2) I can not give path like the above, because I am using jGit to checkout to different commits. So the paths are not fixed and might vary based on the different checkout commits. So the path should be accessed using JGit tree.
Any help would be highly appreciated.
I have one case which is for example to run git command like
$ git log 1.0.201802090918...1.0.201802071240"
to get a differed commits list between release tag 1.0.201802090918 and 1.0.201802071240 under my repo. So I wonder how to code with JGit to gain the same here.
The LogCommand allows to specify the range of commits that it will include. The range need to be given as ObjectIds. And if tags mark the start and end points, the commit IDs that they reference need to be extracted first.
The snippet below illustrates the necessary steps:
ObjectId from = repo.resolve("refs/tags/start-tag");
ObjectId to = repo.resolve("refs/tags/end-tag");
git.log().addRange(from, to).call();
If annotated tags are used, they may have to be unpeeled first as described here: what is the difference between getPeeledObjectId() and getObjectId() of Ref Object?
How can I, with X++, create a sales order from a sales quotation in AX 4.0? I've searched and found the same answer several places, however it seems to be specific to newer versions of AX.
This is what I've found here: https://community.dynamics.com/ax/b/mafsarkhan/archive/2014/04/14/create-sales-order-from-sales-quotation
static void createSalesOrderFromQuote(Args _args)
{
SalesQuotationTable salesQuotationTable = SalesQuotationTable::find("");
SalesQuotationEditLinesForm editLinesForm;
ParmId parmId;
editLinesForm = SalesQuotationEditLinesForm::construct(DocumentStatus::Confirmation);
parmId = editLinesForm.parmId();
editLinesForm.initParmSalesQuotationTable(salesQuotationTable);
editLinesForm.parmTransDate(systemDateGet());
editLinesForm.prePromptInit();
editLinesForm.initParameters(NoYes::No, NoYes::No, NoYes::No, NoYes::No, NoYes::No, '', NoYes::No);
editLinesForm.run();
}
The line editLinesForm.prePromptInit(); wont compile and I guess that is due to only being available in newer versions. I can comment it out and the code will compile and run. However, even though I've added the ID of the SalesQuotationTable like this: ... ::find("123456") It's seems the code converts ALL my quotations to salesorders, however I've yet to confirm this as I've been forced to kill the process to start working again.
I think you may comment out the call to editLinesForm.prePromptInit() from your method.
In order to not post all quotations into sales orders I would try to reproduce the main() method of the SalesQuotationEditLinesForm class in your system, omitting the logic related to datasource.
If I refer to my system I think your code might be missing:
editLinesForm.getLast();
editLinesForm.parmId(parmId);
before calling editLinesForm.run()
I'm trying to use CheckoutCommand the following way:
Git git = new Git(repository);
CheckoutCommand checkoutCommand = git.checkout();
checkoutCommand.setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.SET_UPSTREAM);
checkoutCommand.setStartPoint("origin/" + branchName);
checkoutCommand.setCreateBranch(true);
checkoutCommand.setForce(true);
checkoutCommand.call();
I tried using SetupUpstreamMode.TRACK as well but it still failed.
This results in a strange behaviour:
the repository contents are deleted and instead a clone from each remote branch is created.
Can you please advise?
You are not setting the name of the branch to create, which should result in an exception on call() (is it possible that you are swallowing that?). Add a call like this:
checkoutCommand.setName(branchName);
See the documentation of CheckoutCommand (the above is mentioned here).
Also note that these calls can be chained, so you could also write it like this:
git.checkout().setCreateBranch(true).setName(branchName) // ...
I want to use JGit API to retrieve the tags associated with a specific commit hash (if there is any)?
Please provide code snippet for the same.
Git object model describes tag as an object containing information about specific object ie. commit (among other things) thus it's impossible in pure git to get information you want (commit object don't have information about related tags). This should be done "backwards", take tag object and then refer to specific commit.
So if you want get information about tags specified for particular commit you should iterate over them (tags) and choose appropriate.
List<RevTag> list = git.tagList().call();
ObjectId commitId = ObjectId.fromString("hash");
Collection<ObjectId> commits = new LinkedList<ObjectId>();
for (RevTag tag : list) {
RevObject object = tag.getObject();
if (object.getId().equals(commitId)) {;
commits.add(object.getId());
}
}
If you know that there is exactly one tag for your commit, you could use describe, in more recent versions of JGit (~ November 2013).
Git.wrap(repository).describe().setTarget(ObjectId.fromString("hash")).call()
You could parse the result, to see if a tag exists, but if there can be multiple tags, you should go with Marcins solution.