Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jgit-dev] CommitBuilder Question

On Fri, Jun 24, 2011 at 07:05, Abhishek Bhatnagar <abhatnag@xxxxxxxxxx> wrote:
> On 06/24/2011 12:39 AM, Shawn Pearce wrote:
>> On Thu, Jun 23, 2011 at 13:10, Abhishek Bhatnagar<abhatnag@xxxxxxxxxx>
>>  wrote:
>>> I can't get CommitBuilder to work as advertised. To start with, I created
>>> a
>>> CommitBuilderTest [1].
>>> The use case is:
>>> 1.A commit already exists in the git repo
>>> 2. Create another commit using CommitBuilder Any help is appreciated it.
>>> Feel free to work in the gist itself. You could export it to
>>> org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ if
>>> you want to run it in the proper environment. Thanks Abhishek Bhatnagar
>>> ---------------------------------------------------------------------------------
>>> 1. Available in a gist here:
>> I am unclear about what you are trying to accomplish.
>> The code seems OK to me (I only read it, I didn't run it). It produces
>> a commit that is not attached to any branch.
>> If you wanted to update a branch, you should use the CommitCommand
>> available from a Git object's commit() method. Or start digging into
>> the low level UpdateRef stuff yourself. CommitBuilder is a low-level
>> object, not a higher level API object.
> yup, thanks for the reply Shawn.
> I'm working on stash command for jgit atm, particularly on StashCreate.
> Hence I can't use CommitCommand, as my refUpdate goes to /refs/stash.
> The code included in this thread is simply a fragment of the StashCreate
> code that isn't working. The gist included ends up failing the
> assertTrue(status.getUntracked().size() == 0);
> test.
> So as far as I can tell, I'm doing something wrong. I simply want to create
> a commit in this case; I even tried adding it to the master branch, same
> result.

You'll have to look at how CommitCommand works then, and do similar
sort of logic in your StashCreate to use UpdateRef to modify the
refs/stash reference with your newly created commit. And then you'll
need to use code from CheckoutCommand or ResetCommand to undo the
changes to the working directory and restore back to HEAD.


Back to the top