blob: 684411694f64ca216fb03430df2d2a0ec9ea93ff [file] [log] [blame]
Thomas Harninga00a42a2007-11-22 15:19:40 -05001/*
2 * Implementation of git-merge-ours.sh as builtin
3 *
4 * Copyright (c) 2007 Thomas Harning Jr
5 * Original:
6 * Original Copyright (c) 2005 Junio C Hamano
7 *
8 * Pretend we resolved the heads, but declare our tree trumps everybody else.
9 */
10#include "git-compat-util.h"
11#include "builtin.h"
12
Jonathan Nieder20c7e3d2009-11-09 09:04:45 -060013static const char builtin_merge_ours_usage[] =
14 "git merge-ours <base>... -- HEAD <remote>...";
15
Thomas Harninga00a42a2007-11-22 15:19:40 -050016static const char *diff_index_args[] = {
17 "diff-index", "--quiet", "--cached", "HEAD", "--", NULL
18};
19#define NARGS (ARRAY_SIZE(diff_index_args) - 1)
20
21int cmd_merge_ours(int argc, const char **argv, const char *prefix)
22{
Jonathan Nieder20c7e3d2009-11-09 09:04:45 -060023 if (argc == 2 && !strcmp(argv[1], "-h"))
24 usage(builtin_merge_ours_usage);
25
Thomas Harninga00a42a2007-11-22 15:19:40 -050026 /*
27 * We need to exit with 2 if the index does not match our HEAD tree,
28 * because the current index is what we will be committing as the
29 * merge result.
30 */
31 if (cmd_diff_index(NARGS, diff_index_args, prefix))
32 exit(2);
33 exit(0);
34}