Taka
Taka

Reputation: 7

JGit push does not update files

I've been searching about this topic for a few days now and I can't get a solution. I've looked at this topic too: StackOverflow How to push JGit

The problem is I'm doing a program that should be a github with only the very basic functions, but when I do a push commit messages works fine but if I change the content of some files it does not update on the remote repository.

I use this for commit:

 Repository localRepo = new FileRepository(repository + "\\.git");
 Git git = new Git(localRepo);  
 git.commit().setCommitter(txtCommiter.getText(),"").setMessage(txtCommit.getText()).call();

And I use this for pushing:

Repository localRepo = new FileRepository(this.repository + "\\.git");
Git git = new Git(localRepo);
PushCommand push = git.push();
UsernamePasswordCredentialsProvider user = new UsernamePasswordCredentialsProvider(this.userName, this.pwd);
push.setCredentialsProvider(user);
push.setRemote(this.remote);
push.call();

Anyone can help my with this?

Upvotes: 0

Views: 1949

Answers (1)

robinst
robinst

Reputation: 31417

Have a look if the commits you are creating are correct using git show COMMIT_ID.

If not, the problem is that you didn't include the files you wan to commit with CommitCommand. The following corresponds to git commit -a -m msg:

 git.commit().setAll(true).setMessage(msg).call();

You can also use setOnly(path) to include only certain files or directories in the commit. Call it multiple times for more than one path.

Another option would be if you add the files to the index first to stage it for commit (then you don't have to specify any files in commit):

git.add().addFilepattern(dirA).addFilepattern(fileB).call();

Upvotes: 3

Related Questions