Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [egit-dev] checkout --orphan


> I am looking at possibilities to establish a git repository structure
> where I can collocate R4E code review meta-data with an existing
> repository,
> 
> I am looking for a way in jgit/api to cause the effects of the
> following pair of commands:
> 
>   > git checkout --orphan "branchName"
>   > git rm -rf

Basically, you want to use a dedicated branch for storing R4E code review data?
Assuming a branch name like "refs/codereview/r4e" will be used for storing
the code review data:

// create a RefUpdate object
Repository git = ... a Git repo ...
RefUpdate refUpdate = git.updateRef("refs/codereview/r4e");
refUpdate.setNewObjectId(... commit containing your code review files/folders ...);

// to create a first commit on this branch (without a parent commit)
refUpdate.setExpectedOldObjectId(ObjectId.zeroId());

// to create a next commit on this branch 
refUpdate.setExpectedOldObjectId(... existing commit ...);

// perform the update
result = refUpdate.update();

The result of the update() method must be checked as the update may fail
when the tip of the branch is not pointing to the expectedOldObjectId.
This ensures that concurrent ref updates don't overwrite each other.

I have a Gerrit change (still in review) which contains most of the 
code examples you would need:
https://review.source.android.com/#patch,sidebyside,20045,10,gerrit-server/src/main/java/com/google/gerrit/server/git/CreateCodeReviewNotes.java


Sasa Zivkov




Back to the top