#!/usr/bin/perl
# PODNAME: git-merge-theirs

use strict;
use warnings;

#    Copyright 2012 Grant Street Group, All Rights Reserved.
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, either version 3 of the
#    License, or (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

#
# Implement 'theirs' merge strategy which is the opposite of Git's
# builtin 'ours' strategy.
#
# The idea is to merge two branches making the current branch exactly
# match the other one.  It's used when promoting the entire master branch
# to the test branch.  We checkout the test branch and merge the master
# branch into it using 'theirs'.  This way, neither branch needs to be
# rewound and our conscious decision to choose 'master' over 'test' is
# preserved for future merges.
#
# This command must be called git-merge-theirs so that Git can find it.

my $their_commit = $ARGV[-1];
exec "git read-tree --reset -u $their_commit"
