Thomas Harning | a00a42a | 2007-11-22 15:19:40 -0500 | [diff] [blame] | 1 | /* |
| 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 Nieder | 20c7e3d | 2009-11-09 09:04:45 -0600 | [diff] [blame] | 13 | static const char builtin_merge_ours_usage[] = |
| 14 | "git merge-ours <base>... -- HEAD <remote>..."; |
| 15 | |
Thomas Harning | a00a42a | 2007-11-22 15:19:40 -0500 | [diff] [blame] | 16 | static const char *diff_index_args[] = { |
| 17 | "diff-index", "--quiet", "--cached", "HEAD", "--", NULL |
| 18 | }; |
| 19 | #define NARGS (ARRAY_SIZE(diff_index_args) - 1) |
| 20 | |
| 21 | int cmd_merge_ours(int argc, const char **argv, const char *prefix) |
| 22 | { |
Jonathan Nieder | 20c7e3d | 2009-11-09 09:04:45 -0600 | [diff] [blame] | 23 | if (argc == 2 && !strcmp(argv[1], "-h")) |
| 24 | usage(builtin_merge_ours_usage); |
| 25 | |
Thomas Harning | a00a42a | 2007-11-22 15:19:40 -0500 | [diff] [blame] | 26 | /* |
| 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 | } |