JGit does not pull the remote reset - jgit

I am seeing a strange behaviour, I don't know if it is a bug or a feature.
From machine #1 I do git reset --hard someCommit && git push -f. The reset is then propagated to all machine (I can see the change by doing a git pull or git logfrom another machine).
From machine #2 that runs JGit I perform: git.pull().call() but the reset is not applied and the files on disk are not changed. Also git.log().call() does not point to the reverted commit.
What am I doing wrong?

Like Tim described, you likely need to force fetch on the other computers.
The return value of PushCommand::call() will tell you if and why the push did not succeed.
To force pull in JGit, follow this example:
git.fetch()
.setForce( true )
.setRefSpec( new RefSpec( "refs/heads/someBranch:refs/remotes/origin/someBranch" ) )
.call();
git.reset()
.setMode( ResetType.HARD )
.setRef( "someBranch" )
.call();

I believe that the git.pull.call() command is being rejected. You executed the following commands:
git reset --hard someCommit
git push -f
The first one should completely reset the branch to someCommit. The second one force pushes the reset branch to the remote, rewriting the history of the branch in the process. The keyword here is -f which is short for --force.
Because you rewrote the history of this branch, other computers will no longer be able to do a simple git pull because the base of the branch has changed. So I believe that your JGIT call to git.pull().call() is failing with an error. To fix this, you need to "force" pull the branch on the other computers:
git fetch --all
git checkout someBranch
git reset --hard origin/someBranch

Related

How to make `arc land` check local and phabricator review are in sync?

Consider the following workflow:
make some changes
git add . && git commit -am 'update 1'
arc diff, now local and phabricator code review are in sync
make some further changes and git commit -a --amend --no-edit
arc land and the local amended (unreviewed) changes are happily accepted by Arcanist and gets merged to master.
Apparently, if I don't do --amend in step 4 and create another commit, arc land would fail complaining a mismatch. But I would like to configure Arcanist so that with --amend arc land can fail as well. Is this possible?
It turns out the arc command I am using is monkey patched by my employer and there is a bug in the patch.

pull git subtree, working tree has modification

I've a remote repository let's call it subrepo. I want to include it as subtree in local repository, let's call it mainrepo. I'll put subrepo under the path 'subrepofold/'.
I added as usually the remote using:
git remote add subrepo git#remote.subrepo.git
On mainrepo I've only a branch (master). I added and committed all:
git add --all
git commit -m "message"
git status
On branch master
nothing to commit, working directory clean
git diff-index HEAD --exit-code --quiet
Give me no output. Running:
git subtree pull --prefix="subrepofold" subrepo master --squash
I get the following message:
Working tree has modifications. Cannot add.
I know it seems to be the exact problem described here, but none of the replies seems to resolve the problem.

Rstudio greyed out Git commands and (No branch)

I am currently struggling with getting Rstudio to work with my git repositories. When I set up a new project and assign the git repository, the branch is set on Master and the commit, pull, and push buttons are all active. Everything works just fine. Then, at some point the branch is switched to (No Branch) and the commit, pull, and push buttons are greyed out (shown below). This happens to every single git project I make. Works at first then is greyed out.
I am still able to use git commands from Shell, but the GUI interface is not working.
I have spent some time looking through customer support forums and Googling the problem. One site that I found (https://www.r-bloggers.com/things-i-forget-pushpull-greyed-out-in-rstudio/) indicated that there is an issue with the configuration list. However, when I do git config --list, I find that I do have branch.master.remote=origin and branch.master.merge=refs/heads/master at the bottom of the configuration.
I also attempted a git push -u origin master, but that did not work either.
I use RStudio and github daily, and I would be so pleased if the GUI interface was working properly again.
I would be very grateful if someone could help me problem solve this issue.
EDIT: I am using OSX 10.9 Mavericks and Rstudio Version 0.99.903.
I had a similar problem with a repo I had already configured locally and pushed and pulled from/to it using CLI (although I didn't have the problem of being detached from a branch) and I solved it by doing the following:
Open your console and navigate to your repo
Make some commit
Make a push using -u (i.e. --set-upstream) flag, eg: git push origin master -u
Open Rstudio (or restart it if it was open while performing the previous step) and you'll see the push and pull icons are no longer greyed out.
Then, at some point the branch is switched to (No Branch) and the commit, pull, and push buttons are greyed out (shown below).
That is typical of a detached HEAD branch: see "Why did my Git repo enter a detached HEAD state?".
Revert to the command-line and check your git status.
You can easily recover from this by a checkout of a branch.
Or by forcing a branch to your current detached commit
git branch -f branch-name HEAD
git checkout branch-name
Then switch back to RStudio: all options should be available again.
As commented:
Tt turns out to be an RSA key issue.
The wrong key was in the Rstudio Config, which explains how Shell would work but not the Rstudio interface.
I just wanted to provide an update in case anyone in the future had a similar problem. While the answer provided earlier resulted in another temporary fix, I ultimately had to wipe my hard drive; reinstall the operating system; reinstall git, R, RStudio, and reconnect to my Github account before it would consistently work.
My solution may have been a bit overkill, but I have not had an issue with it since.
I had the same issue today and found this post. I am going to share how I solve it:
on terminal (Git) type the following:
$ git config --global user.name
(it should return your Github username)
if username isn't correct just type
$ git config --global user.name "correct_username"
then type
$ git config --global user.email
(it should return an email associated to your GitHub account)
I found a typo in my email and fixed it by typing
$ git config --global user.email "correct_email"
Then I added the origin (this you get it from GitHub)
$ git remote add origin https://github.com/my_username/my_repository.git
Then I setup the branch, most used ones are main and master, in my case it is main
$ git branch -M main
then I pushed from the terminal
$ git push -u origin main
after that my pull and push buttons are active.
I hope this can save some time for others.

How can I recover if I made a mistake in git flow init?

I've run git init and made a mistake selecting the first branch. Now I want to rerun it to change the settings, but it never asks the first question again.
Which branch should be used for bringing forth production releases?
- develop
Branch name for production releases: [] develop
Which branch should be used for integration of the "next release"?
Branch name for "next release" development: [develop] ^C
Lymnaea:boxes (develop) $ git flow init
Which branch should be used for integration of the "next release"?
Branch name for "next release" development: [develop]
Production and integration branches should differ.
How can I undo the first init run so that I can set the branch to master?
In the end I found the answer in this question. It's not entirely a duplicate, so I'll leave this here for the next person that cannot find the right keywords.
git flow init -f # will force re-initialization
If you want to do it manually, you can use git config -e.

Errors when using RStudio's Git tools

When attempting to push to GitHub from RStudio, I get the following errors.
error: unable to read askpass response from 'rpostback-askpass'
fatal: could not read Username for 'https://github.com':
No such device or address
RStudio has my origin as
https://github.com/rmscriven/other.git
when it actually should be
https://github.com/rmscriven/saber.git
RStudio will not allow me to change the origin from the version control system. Here is what it shows:
Is it possible to change my GitHub origin url from RStudio?
Thanks to the pro tip provided by #krlmlr in the comments,
Use an empty target directory. Look for "clone URL" on your GitHub project page, perhaps choose the SSH variant.
I clicked "clone url" on GitHub once, nothing. Then again, nothing. And once again for good measure, nothing. So I went to the terminal, read the man git help file, and decided to change my password and reconfigure. These are the lines I ran, and it was successful.
git config --global user.name <myuser.name>
git config --global user.email <myuser.email>
git clone https://github.com/rmscriven/saber.git
git pull
Then I went to RStudio and it allowed me to clone my repository, and change the URL of my version control setting. Here's a colorful pic
New project -> Version Control -> Git -> Create Project
Next, magic happened, and I had a copy of my package which I very carefully removed to prepare to push the development tarball to GitHub. Rock on.
#krlmlr, I thank you for nudging me in the right direction. Now I feel like I'm actually doing it the right way. :)
And for fun, try saying 'rpostback-askpass' ten times fast.
I had the same problem and for me these two simple steps worked great:
Add the SSH key from RStudio to my github account.
Change the origin URL and use the -u flag for push/pull once (solution found here).
For 1., in RStudio go to Tools → Global Options... → Git/SVN → view public key, and copy the key. In your browser of choice, logged in on Github, click Edit Profile → SSH keys and paste the copied key here.
For 2., back in RStudio, click Tools → Shell… , then enter:
git remote add origin https://github.com/myname/test.git
git config remote.origin.url git#github.com:myname/test.git
git pull -u origin master
git push -u origin master
Of course, change "myname" to your username and "test.git" to the name of your project. (Or even "github.com" to the URL of your institute's github or similar.)
After doing this once, the Push/Pull buttons in RStudio should work and you don't need the shell anymore!
I've been running into this issue on multiple computers now, with a remote that doesn't support SSH and thus can't leverage password-less login.
The problem in this case is that by default, git ask for the password interactively, and RStudio can't display this graphically. The trick is to use git's credential storage system.
For instance on Mac OS X:
git config --global credential.helper osxkeychain
On Linux one could use the gnome-keyring integration.

Resources