0

As a followup to an earlier question, I'm trying to update one reference (e.g. release) to point to another reference (e.g. master).


If I have a master and a release branch, and master is a single commit ahead of release, I'd like to "fast-forward" release to master. I try this:

r = Rugged::Repository.new(".") # assume we're on the `release` branch
r.references.update(r.head.resolve, r.branches['master'].target_id)

This almost works, but leaves my repo in a state like this:

On branch release
Your branch is ahead of 'origin/release' by 1 commit.
  (use "git push" to publish your local commits)
 Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    modified:   file

Am I missing a step? I'm expecting my staging area to be "clean".

I've tried r.index.write_tree(r) and r.index.write, but no dice.

Max
  • 4,882
  • 2
  • 29
  • 43
  • Is that the totality of you're code? You seem to not be checking out the target, so the index contains the previous data. I don't understand why, since you seem to do the checkout step in the question you linked to. – Edward Thomson Jan 22 '15 at 23:45
  • possible duplicate of [Performing a "fast-forward" merge with Rugged](http://stackoverflow.com/questions/27072920/performing-a-fast-forward-merge-with-rugged) – Edward Thomson Jan 22 '15 at 23:47
  • I don't follow -- I already stated I'm assuming the release branch is already checked out when the Repository is instantiated. – Max Jan 23 '15 at 00:40
  • This is a tricky terminology. It's not checked out, you're "on the release branch", but the contents from master aren't there yet. libgit2's checkout functionality will update the working directory and the index with the new contents. If you don't do that, status will show that you have changes. – Edward Thomson Jan 23 '15 at 01:03
  • So...what do I need to do? I tried `r.head = 'refs/heads/release'`, but that didn't seem to change anything. – Max Jan 23 '15 at 01:16
  • Hmm...calling `r.reset(r.head.target, :hard)` as mentioned in the comment [here](https://stackoverflow.com/questions/27971814/rugged-merge-commit-from-origin-does-not-update-working-tree?rq=1#comment44340761_27971814) seems to do what I want. Is that the wrong approach? – Max Jan 23 '15 at 01:22
  • What's wrong with the answer to your other question? – Edward Thomson Jan 23 '15 at 02:44
  • It leaves a dirty index, as I pointed out in this question. – Max Jan 23 '15 at 04:52
  • Your code - in this question - does not show you doing a checkout. Can you post the actual code that you're using? – Edward Thomson Jan 23 '15 at 04:54
  • Just prefix the first line with "git checkout release" on the command line. – Max Jan 23 '15 at 17:58
  • Okay. So use the code in the answer to your other question which calls *Rugged checkout*, that will update the index and workdir. – Edward Thomson Jan 23 '15 at 18:09
  • No change; `r.checkout_tree(r.branches["release"].target)` does nothing. – Max Jan 23 '15 at 18:18

0 Answers0