last day (15 days later) » 

5:55 PM
0
A: Using JGit : How to push a specific commit to a remote repo

Rüdiger HerrmannIt seems that this is currently not possible with JGit. (BTW, are you sure that native Git accepts a ref-spec like SHA-1:refs/heads/*, the man page does not explicitly state so) Though there is a setRefSpec() method, it does not accept commit ids. To work around this limitation, you could tempor...

 
Hi...regarding native Git's ref acceptance, I found this link : stackoverflow.com/questions/3230074/git-pushing-specific-commit, which says that I can do the following with the native git: git push <remotename> <commit SHA>:<remotebranchname> I first tries a RefSpec like SHA-1:master (to mimic "git push <remotename> SHA-1:master"), but JGit's PushResult found "master" a funny ref. That's why I was trying the following approach : SHA-1:refs/remotes/__my__remote__name__/master
 
Hm, I think I have to revoke my statement about JGit and commit ids's in ref-specs. I was able to call a PushCommand with a ref-spec like new RefSpec( commitToPush.name() + ":refs/remotes/origin/master" ). What exception exactly do you get with SHA-1:refs/remotes/__my__remote__name__/master?
 
Can you please tell me what the value of "commitToPush.name()" looks like for you? I just tried to get repo.getRef(shaIdOfTheCommitToPush), but it returned null for me.
Well, I got the exception when I used "SHA-1:master" as the refspec and "my_remote" as the remote name. It said it found "master" a funny ref. When I used "SHA-1:refs/remotes/__my__remote__name__/master", it didn't give any errors in the PushResult, but it also did not do the actual pushing to the remote repo.
 
commitToPush.name() is the SHA-1 of a commit like 3262861b54556e219b8fea1ffc0e39050cff44d5for example. getRef() will only resolve refs (tags, branches, 'HEAD', etc.). Why do you call getRef? If your shaIdOfTheCommitToPush is a commit id, you can create a ref-spec just like new RefSpec( shaIdOfTheCommitToPush + ":refs/remotes/..." );
 
I was just trying getRef(shaIdOfTheCommitToPush) to see if its getName() gets some sort of formatted name that PushCommand's RefSpec may like better. I was trying it because new RefSpec( shaIdOfTheCommitToPush + ":refs/remotes/__my_remote__name/master" ); didn't work - however, this did not give me any error too. It just didn't push the content to the remote repo :-(
 
5:55 PM
You can inspect the PushResults returned from PushCommand#call() to see why nothing was pushed.
 
wow...didn't know a 1:1 chat option was also there
So, on my local repo, I have the state "......C3 -> C2 -> C1 -> Head", let's say...and my remote repo is currently at Head=C3.

I am trying to push "C2:refs/remotes/origin/master" right now. between C3 and C2, there is a small difference (in terms of the commit made).

The PushCommand is going on right now (with a TextProgressMonitor set on it). God knows why it's writing so much to the remote repo : "Writing objects: 47% ( 6732/14314)"

I am waiting to inspect the PushResult.
Again, the PushCommand got completed. PushResult shows the following OK result :

refs/remotes/__my_remote__repo__/master=RemoteRefUpdate[remoteName=refs/remotes/__my_remote__repo__/master, OK, (null)...c54bddfc1530b0885352f4672485fa93cc18c27f2, fastForward, srcRef=c54bddfc1530b0885352f4672485fa93cc18c27f2, message=null]

but no changes reflect on my remote repo. :-(
 
6:11 PM
Well, I'm new to this as well. SO suggested to convert the lengthy comments in to a chat - and here we go...
 
do u see anything I am still missing? TextProgressMonitor showed it proceeding upto 100% without any issues:

Counting objects: 14314
Finding sources: 100% (14314/14314)
Getting sizes: 100% (4722/4722)
Compressing objects: 99% (19789/19800)
Writing objects: 100% (14314/14314)

Why aren't the changes making it to the remote repo? :-(
 
The PushResult looks good. How do you check the remote repo?
 
by accessing <https://github.com/my_remote__repo/commits/master>
If I try the same run again, it shows :

refs/remotes/__my_remote__repo__/master=RemoteRefUpdate[remoteName=refs/remotes/__my_remote__repo__/master, UP_TO_DATE, (null)...c54bddfc1530b0885352f4672485fa93cc18c27f2, srcRef=c54bddfc1530b0885352f4672485fa93cc18c27f2, message=null]

OK changed to UP_TO_DATE, as expected. The only issue is that I don't see my changes pushed on <https://github.com/my_remote__repo/commits/master>
 
Do you see commits/master on GitHub at all? Or does is just point to the wrong commit id?
 
6:28 PM
I see commits/master on GitHub. The top entry points to what it was before I did my remote pushes using the RefSpec approach here.
 
What if you clone the remote again into another local repo, just to see what commits/master points at?
 
1 min
if I re-clone it, I still see the old head on the master branch
 
Well, then it looks like a bug in JGit. If you can come up with a standalone snippet to reproduce the problem, I recommend to open a bugzilla (eclipse.org/jgit/support)
 
In comparison, git push my_remote_repo 12ab5fb:master works so smoothly and the changes perfectly show up on the github.
I am wondering how I'll make a standalone snippet to reproduce it. I'd like to. Any suggestions? Using both file-system repos perhaps, no?
 
6:52 PM
also, didn't you say that PushCommand with a `SHA-1:refs/remotes/__my_remote__repo__/master` refspec worked for you - when you said in the original stackoverflow thread "I was able to call a PushCommand with a ref-spec like new RefSpec( commitToPush.name() + ":refs/remotes/origin/master" )"?

How did it work for you?
before I forget (as it's much past midnight here now) : thanks a lot for your inputs on this.
 
7:15 PM
Yes, to reproduce I'd use a JUnit test case with two local repos (you may use the TemporaryFolder rule to create the directories)
 
will try...thanks
 
As for why it worked for me: I didn't check the result. Just got no exception and thought it worked. I'll need to re-check.
 
I thought so too: just wanted to cross-check (because it's the same for me too - everything looks normal in progress-monitor and PushResult - just the content doesn't really reach the remote repo)
closing the chat from my side now..time to sleep...thanks again...
 
8:05 PM
Hi, it got solved:
debugged all inside JGit's transport classes and then switched from

the earlier : `commitId + ":refs/remotes/__my_remote__repo__/master"`

to, now: `commitId + ":refs/heads/master"`

Now, the content shows up correctly on <https://github.com/my_remote__repo/commits/master>.

Yay! Thanks for your help.
 

last day (15 days later) »