applicationsonline/librarian — Issue #44: Use 'git reset --hard' instead of merge to avoid possibility of merge conflicts
Author: TylerRick
Created: 2012-03-09 16:37:13+00:00
State: open

This is the error I was getting:

```
> librarian-chef update
/home/tyler/.rvm/gems/ruby-1.9.3-p125/gems/librarian-0.0.14/lib/librarian/source/git/repository.rb:102:in `block in run!': StandardError
from /home/tyler/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/open3.rb:208:in `popen_run'
from /home/tyler/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/open3.rb:90:in `popen3'
from /home/tyler/.rvm/gems/ruby-1.9.3-p125/gems/librarian-0.0.14/lib/librarian/source/git/repository.rb:101:in `run!'
from /home/tyler/.rvm/gems/ruby-1.9.3-p125/gems/librarian-0.0.14/lib/librarian/source/git/repository.rb:62:in `block in merge!'
from /home/tyler/.rvm/gems/ruby-1.9.3-p125/gems/librarian-0.0.14/lib/librarian/source/git/repository.rb:110:in `block in within'
from /home/tyler/.rvm/gems/ruby-1.9.3-p125/gems/librarian-0.0.14/lib/librarian/source/git/repository.rb:110:in `chdir'
from /home/tyler/.rvm/gems/ruby-1.9.3-p125/gems/librarian-0.0.14/lib/librarian/source/git/repository.rb:110:in `within'
from /home/tyler/.rvm/gems/ruby-1.9.3-p125/gems/librarian-0.0.14/lib/librarian/source/git/repository.rb:60:in `merge!'
```

Had to use -verbose to actually figure out what command it failed on and which directory it was running in...

```
[Librarian] Running `git checkout master --force --quiet` in ../tmp/librarian/cache/source/git/760ea73281ddef714f6380749d5ef4f0
[Librarian] Running `git merge origin/master --quiet` in ../tmp/librarian/cache/source/git/760ea73281ddef714f6380749d5ef4f0
```

When I manually inspected that directory, this is what I noticed:

```
> pushd ../tmp/librarian/cache/source/git/760ea73281ddef714f6380749d5ef4f0
> git st
# On branch master
# Your branch and 'origin/master' have diverged,
# and have 1 and 1 different commit(s) each, respectively.
#
# Unmerged paths:
# (use "git add/rm ..." as appropriate to mark resolution)
#
#	both modified: libraries/search.rb
```

**IMHO, git merge is too risky to use for automated processes like librarian (and is only meant for interactive use by developers) and git reset --hard should always be used instead.** I think that's what capistrano uses too, IIRC...

I fixed it for myself by modifying file ~/.rvm/gems/ruby-1.9.3-p125/gems/librarian-0.0.14/lib/librarian/source/git/repository.rb and changing this:

```ruby
def merge!(reference)
within do
command = "merge #{reference}"
run!(command)
end
end
```

into this:

```ruby
def merge!(reference)
within do
command = "reset --hard #{reference}"
run!(command)
end
end
```