Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jgit-dev] creating a new branch fails with LOCK_FAILURE if branch already exists

Thanks for the explanations. That was helpful :-)

-----Original Message-----
From: Robin Rosenberg [mailto:robin.rosenberg@xxxxxxxxxx] 
Sent: Mittwoch, 4. Januar 2012 17:43
To: Shawn Pearce
Cc: Kempin, Edwin; JGit Developers list
Subject: Re: [jgit-dev] creating a new branch fails with LOCK_FAILURE if branch already exists

Shawn Pearce skrev 2012-01-04 16.27:
> On Wed, Jan 4, 2012 at 06:30, Kempin, Edwin<edwin.kempin@xxxxxxx>  wrote:
>> this is how we create a new branch:
>> final RefUpdate u = repo.updateRef(refname);
>> u.setExpectedOldObjectId(ObjectId.zeroId());
>> u.setNewObjectId(object.copy());
>> u.setRefLogIdent(refLogIdent);
>> u.setRefLogMessage("some message", false);
>> final RefUpdate.Result result = u.update(rw);
>> switch (result) {
>>   case FAST_FORWARD:
>>   case NEW:
>>   case NO_CHANGE:
>>     // branch creation was successful
>>     ...
>>     break;
>>   default: {
>>     throw new IOException(;
>>   }
>> }
>> When the branch creation fails because a branch with the name already exists LOCK_FAILURE is returned as result.
> Yes. Because LOCK_FAILURE is returned when the reference's current
> value does not match the expected old ObjectId. Using
> ObjectId.zeroId() is only special in terms of looking for the
> reference to not exist at all, otherwise it is treated the same as if
> any other ObjectId was used and the reference no longer points at that
> ObjectId.

I.e do not call setExpectedOldObjectId() at all to create the
branch regardless of whether it is new or not.

-- robin

Back to the top