Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jgit-dev] Commit to bare repo.

Thanks, but how can i do that? 

I'm trying to commit change in one file with info only about path and file content. I don't know anything about others files in repo.


On Wed, Oct 16, 2013 at 4:18 PM, Yi, EungJun <semtlenori@xxxxxxxxx> wrote:
Append all files into the new tree, not only README.

A commit is not a changeset but a snapshot, so its root tree should have all files if you don't want delete them.



On Wed, Oct 16, 2013 at 10:28 PM, Darek Sztwiorok <d.sztwiorok@xxxxxxxxx> wrote:
Hi Folks.

I've got some problems during trying to write some sample code to make commit to existing bare repo with commits. 

Here's my code: 

public static void main(String[] args) throws Exception {
        Repository repository = new FileRepositoryBuilder().
                setGitDir(new File("/home/tweek/test.git/")).
                readEnvironment().findGitDir().build();

        System.out.println(repository.getDirectory());

        ObjectInserter inserter = repository.newObjectInserter();

        byte[] data = "">
        ObjectId fileId = inserter.insert(Constants.OBJ_BLOB, data, 0, data.length);

        TreeFormatter formatter = new TreeFormatter();
        formatter.append("README", FileMode.REGULAR_FILE, fileId);

        ObjectId treeId = inserter.insert(formatter);

        AnyObjectId headID = repository.resolve(Constants.HEAD);
        System.out.println(headID);

        PersonIdent person = new PersonIdent("Your Name", "noreply@xxxxxxxxxxx");
        CommitBuilder commit = new CommitBuilder();
        commit.setTreeId(treeId);
        commit.setAuthor(person);
        commit.setCommitter(person);
        commit.setMessage("Commit");
        commit.setParentId(headID.toObjectId());

        ObjectId commitId = inserter.insert(commit);
        inserter.flush();

        RefUpdate ru = repository.updateRef(Constants.HEAD);
        ru.setForceUpdate(false);
        ru.setRefLogIdent(person);
        ru.setNewObjectId(commitId);
        ru.setExpectedOldObjectId(headID);

        System.out.println(ru.update());
    }

Everything is looking good. Git log command at bare repo returned proper tree.

But the problem is when i make git pull at working copy - all files except one with changes (README) has been deleted. 

Can anyone tell me what i'm doing wrong??

--
Kind Regards
Darek Sztwiorok

_______________________________________________
jgit-dev mailing list
jgit-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/jgit-dev





--
pozdrawiam
Darek Sztwiorok

Back to the top