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

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.setRefLogMessage("some message", false);
final RefUpdate.Result result = u.update(rw);
switch (result) {
  case NEW:
  case NO_CHANGE:
    // branch creation was successful
  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

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