2007-11-22 21:19:40 +01:00
|
|
|
/*
|
|
|
|
* Implementation of git-merge-ours.sh as builtin
|
|
|
|
*
|
|
|
|
* Copyright (c) 2007 Thomas Harning Jr
|
|
|
|
* Original:
|
|
|
|
* Original Copyright (c) 2005 Junio C Hamano
|
|
|
|
*
|
|
|
|
* Pretend we resolved the heads, but declare our tree trumps everybody else.
|
|
|
|
*/
|
|
|
|
#include "git-compat-util.h"
|
|
|
|
#include "builtin.h"
|
2017-10-10 05:04:48 +02:00
|
|
|
#include "diff.h"
|
2007-11-22 21:19:40 +01:00
|
|
|
|
2009-11-09 16:04:45 +01:00
|
|
|
static const char builtin_merge_ours_usage[] =
|
|
|
|
"git merge-ours <base>... -- HEAD <remote>...";
|
|
|
|
|
builtins: mark unused prefix parameters
All builtins receive a "prefix" parameter, but it is only useful if they
need to adjust filenames given by the user on the command line. For
builtins that do not even call parse_options(), they often don't look at
the prefix at all, and -Wunused-parameter complains.
Let's annotate those to silence the compiler warning. I gave a quick
scan of each of these cases, and it seems like they don't have anything
they _should_ be using the prefix for (i.e., there is no hidden bug that
we are missing). The only questionable cases I saw were:
- in git-unpack-file, we create a tempfile which will always be at the
root of the repository, even if the command is run from a subdir.
Arguably this should be created in the subdir from which we're run
(as we report the path only as a relative name). However, nobody has
complained, and I'm hesitant to change something that is deep
plumbing going back to April 2005 (though I think within our
scripts, the sole caller in git-merge-one-file would be OK, as it
moves to the toplevel itself).
- in fetch-pack, local-filesystem remotes are taken as relative to the
project root, not the current directory. So:
git init server.git
[...put stuff in server.git...]
git init client.git
cd client.git
mkdir subdir
cd subdir
git fetch-pack ../../server.git ...
won't work, as we quietly move to the top of the repository before
interpreting the path (so "../server.git" would work). This is
weird, but again, nobody has complained and this is how it has
always worked. And this is how "git fetch" works, too. Plus it
raises questions about how a configured remote like:
git config remote.origin.url ../server.git
should behave. I can certainly come up with a reasonable set of
behavior, but it may not be worth stirring up complications in a
plumbing tool.
So I've left the behavior untouched in both of those cases. If anybody
really wants to revisit them, it's easy enough to drop the UNUSED
marker. This commit is just about removing them as obstacles to turning
on -Wunused-parameter all the time.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-03-28 22:56:55 +02:00
|
|
|
int cmd_merge_ours(int argc, const char **argv, const char *prefix UNUSED)
|
2007-11-22 21:19:40 +01:00
|
|
|
{
|
2009-11-09 16:04:45 +01:00
|
|
|
if (argc == 2 && !strcmp(argv[1], "-h"))
|
|
|
|
usage(builtin_merge_ours_usage);
|
|
|
|
|
2007-11-22 21:19:40 +01:00
|
|
|
/*
|
2017-10-10 05:04:48 +02:00
|
|
|
* The contents of the current index becomes the tree we
|
|
|
|
* commit. The index must match HEAD, or this merge cannot go
|
|
|
|
* through.
|
2007-11-22 21:19:40 +01:00
|
|
|
*/
|
2022-11-19 14:07:38 +01:00
|
|
|
if (repo_read_index(the_repository) < 0)
|
2017-10-10 05:04:48 +02:00
|
|
|
die_errno("read_cache failed");
|
2018-11-10 06:49:04 +01:00
|
|
|
if (index_differs_from(the_repository, "HEAD", NULL, 0))
|
2021-06-08 12:48:03 +02:00
|
|
|
return 2;
|
|
|
|
return 0;
|
2007-11-22 21:19:40 +01:00
|
|
|
}
|