Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[egit-dev] Using the Java API to commit files to a repo

Hi,
I'm trying to use the org.eclipse.egit.github.core Java API.
I have a repo that I own and want to use the API to take a given file (an
updated version of something already in the repo) and then commit the file
to the repo so that it replaces the original version.
I was hoping if someone might give me some clues as to what classes and
methods I should be using here.

I've looked through the API docs and created some code that I've
reproduced below as a start. It throws the error "Error with 'tree' field
in Commit resource", although I never really expected it to run.



public void makeConnection() throws IOException
{
	client.setCredentials("smith", "password");
 
	RepositoryService service = new	RepositoryService(client);
 
 
	
	IRepositoryIdProvider repoId = new RepositoryId("smith","test");
	Repository repo = service.getRepository(repoId);
 
	
	CommitFile f = new CommitFile();
	f.setFilename("file.txt");
 
	List<CommitFile> filesToCommit = new ArrayList<CommitFile>();
	filesToCommit.add(f);
 
	
	Commit c = new Commit();
	CommitUser cUser = new CommitUser();
	cUser.setName("smith");
	c.setAuthor(cUser);
	c.setMessage("Testing commit");
 
	
	RepositoryCommit rc = new RepositoryCommit();
	User user = new User();
	user.setName("smith");
	rc.setAuthor(user);
	rc.setFiles(filesToCommit);
	rc.setCommit(c);
 
	
	DataService ds = new DataService(client);
	ds.createCommit(repoId, c);
 
}


I'm not quite sure if I'm on the right track, but was hoping if someone
might point me in the right direction, or give me some sample code that
might see me on my way.


Many thanks,
Graham




Back to the top