summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0cf8581)
raw | patch | inline | side by side (parent: 0cf8581)
author | Junio C Hamano <gitster@pobox.com> | |
Mon, 1 Sep 2008 02:32:40 +0000 (19:32 -0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 1 Sep 2008 03:09:21 +0000 (20:09 -0700) |
This new option does essentially the same thing as -m option when checking
unmerged paths out of the index, but it uses the specified style instead
of configured merge.conflictstyle.
Setting "merge.conflictstyle" to "diff3" is usually less useful than using
the default "merge" style, because the latter allows a conflict that
results by both sides changing the same region in a very similar way to
get simplified substancially by reducing the common lines. However, when
one side removed a group of lines (perhaps a function was moved to some
other file) while the other side modified it, the default "merge" style
does not give any clue as to why the hunk is left conflicting. You would
need the original to understand what is going on.
The recommended use would be not to set merge.conflictstyle variable so
that you would usually use the default "merge" style conflict, and when
the result in a path in a particular merge is too hard to understand, use
"git checkout --conflict=diff3 $path" to check it out with the original to
review what is going on.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
unmerged paths out of the index, but it uses the specified style instead
of configured merge.conflictstyle.
Setting "merge.conflictstyle" to "diff3" is usually less useful than using
the default "merge" style, because the latter allows a conflict that
results by both sides changing the same region in a very similar way to
get simplified substancially by reducing the common lines. However, when
one side removed a group of lines (perhaps a function was moved to some
other file) while the other side modified it, the default "merge" style
does not give any clue as to why the hunk is left conflicting. You would
need the original to understand what is going on.
The recommended use would be not to set merge.conflictstyle variable so
that you would usually use the default "merge" style conflict, and when
the result in a path in a particular merge is too hard to understand, use
"git checkout --conflict=diff3 $path" to check it out with the original to
review what is going on.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-checkout.txt | patch | blob | history | |
builtin-checkout.c | patch | blob | history | |
t/t7201-co.sh | patch | blob | history |
index c884862e2fb91831c3962599507b4034d4bcb77e..13b106d6264686da90a543d9a84670348eba6939 100644 (file)
--------
[verse]
'git checkout' [-q] [-f] [[--track | --no-track] -b <new_branch> [-l]] [-m] [<branch>]
-'git checkout' [-f|--ours|--theirs|-m] [<tree-ish>] [--] <paths>...
+'git checkout' [-f|--ours|--theirs|-m|--conflict=<style>] [<tree-ish>] [--] <paths>...
DESCRIPTION
-----------
based sha1 expressions such as "<branchname>@\{yesterday}".
-m::
+--merge::
When switching branches,
if you have local modifications to one or more files that
are different between the current branch and the branch to
When checking out paths from the index, this option lets you recreate
the conflicted merge in the specified paths.
+--conflict=<style>::
+ The same as --merge option above, but changes the way the
+ conflicting hunks are presented, overriding the
+ merge.conflictstyle configuration variable. Possible values are
+ "merge" (default) and "diff3" (in addition to what is shown by
+ "merge" style, shows the original contents).
+
<new_branch>::
Name for the new branch.
diff --git a/builtin-checkout.c b/builtin-checkout.c
index b957193155f799ebea0cabcc7496408d4d96d599..79214327b0d99369b3ce384ed1900342f5874c87 100644 (file)
--- a/builtin-checkout.c
+++ b/builtin-checkout.c
const char *arg;
struct branch_info new;
struct tree *source_tree = NULL;
+ char *conflict_style = NULL;
struct option options[] = {
OPT__QUIET(&opts.quiet),
OPT_STRING('b', NULL, &opts.new_branch, "new branch", "branch"),
OPT_SET_INT('3', "theirs", &opts.writeout_stage, "stage",
3),
OPT_BOOLEAN('f', NULL, &opts.force, "force"),
- OPT_BOOLEAN('m', NULL, &opts.merge, "merge"),
+ OPT_BOOLEAN('m', "merge", &opts.merge, "merge"),
+ OPT_STRING(0, "conflict", &conflict_style, "style",
+ "conflict style (merge or diff3)"),
OPT_END(),
};
int has_dash_dash;
argc = parse_options(argc, argv, options, checkout_usage,
PARSE_OPT_KEEP_DASHDASH);
+ if (conflict_style) {
+ opts.merge = 1; /* implied */
+ git_xmerge_config("merge.conflictstyle", conflict_style, NULL);
+ }
+
if (!opts.new_branch && (opts.track != git_branch_track))
die("git checkout: --track and --no-track require -b");
diff --git a/t/t7201-co.sh b/t/t7201-co.sh
index 1d4ff6e8d30ce49a2792107be1c23a66b1df3a8b..ac49311cf2c845475eed00ce5b7d8f364770d1c4 100755 (executable)
--- a/t/t7201-co.sh
+++ b/t/t7201-co.sh
test refs/heads/delete-me = "$(git symbolic-ref HEAD)" &&
test_must_fail git checkout --track -b track'
-test_expect_success 'checkout an unmerged path should fail' '
+setup_conflicting_index () {
rm -f .git/index &&
O=$(echo original | git hash-object -w --stdin) &&
A=$(echo ourside | git hash-object -w --stdin) &&
echo "100644 $A 2 file" &&
echo "100644 $B 3 file" &&
echo "100644 $A 0 filf"
- ) | git update-index --index-info &&
+ ) | git update-index --index-info
+}
+
+test_expect_success 'checkout an unmerged path should fail' '
+ setup_conflicting_index &&
echo "none of the above" >sample &&
cat sample >fild &&
cat sample >file &&
'
test_expect_success 'checkout with an unmerged path can be ignored' '
- rm -f .git/index &&
- O=$(echo original | git hash-object -w --stdin) &&
- A=$(echo ourside | git hash-object -w --stdin) &&
- B=$(echo theirside | git hash-object -w --stdin) &&
- (
- echo "100644 $A 0 fild" &&
- echo "100644 $O 1 file" &&
- echo "100644 $A 2 file" &&
- echo "100644 $B 3 file" &&
- echo "100644 $A 0 filf"
- ) | git update-index --index-info &&
+ setup_conflicting_index &&
echo "none of the above" >sample &&
echo ourside >expect &&
cat sample >fild &&
'
test_expect_success 'checkout unmerged stage' '
- rm -f .git/index &&
- O=$(echo original | git hash-object -w --stdin) &&
- A=$(echo ourside | git hash-object -w --stdin) &&
- B=$(echo theirside | git hash-object -w --stdin) &&
- (
- echo "100644 $A 0 fild" &&
- echo "100644 $O 1 file" &&
- echo "100644 $A 2 file" &&
- echo "100644 $B 3 file" &&
- echo "100644 $A 0 filf"
- ) | git update-index --index-info &&
+ setup_conflicting_index &&
echo "none of the above" >sample &&
echo ourside >expect &&
cat sample >fild &&
'
test_expect_success 'checkout with --merge' '
- rm -f .git/index &&
- O=$(echo original | git hash-object -w --stdin) &&
- A=$(echo ourside | git hash-object -w --stdin) &&
- B=$(echo theirside | git hash-object -w --stdin) &&
- (
- echo "100644 $A 0 fild" &&
- echo "100644 $O 1 file" &&
- echo "100644 $A 2 file" &&
- echo "100644 $B 3 file" &&
- echo "100644 $A 0 filf"
- ) | git update-index --index-info &&
+ setup_conflicting_index &&
echo "none of the above" >sample &&
echo ourside >expect &&
cat sample >fild &&
test_expect_success 'checkout with --merge, in diff3 -m style' '
git config merge.conflictstyle diff3 &&
- rm -f .git/index &&
- O=$(echo original | git hash-object -w --stdin) &&
- A=$(echo ourside | git hash-object -w --stdin) &&
- B=$(echo theirside | git hash-object -w --stdin) &&
- (
- echo "100644 $A 0 fild" &&
- echo "100644 $O 1 file" &&
- echo "100644 $A 2 file" &&
- echo "100644 $B 3 file" &&
- echo "100644 $A 0 filf"
- ) | git update-index --index-info &&
+ setup_conflicting_index &&
echo "none of the above" >sample &&
echo ourside >expect &&
cat sample >fild &&
test_cmp merged file
'
+test_expect_success 'checkout --conflict=merge, overriding config' '
+ git config merge.conflictstyle diff3 &&
+ setup_conflicting_index &&
+ echo "none of the above" >sample &&
+ echo ourside >expect &&
+ cat sample >fild &&
+ cat sample >file &&
+ cat sample >filf &&
+ git checkout --conflict=merge -- fild file filf &&
+ (
+ echo "<<<<<<< ours"
+ echo ourside
+ echo "======="
+ echo theirside
+ echo ">>>>>>> theirs"
+ ) >merged &&
+ test_cmp expect fild &&
+ test_cmp expect filf &&
+ test_cmp merged file
+'
+
+test_expect_success 'checkout --conflict=diff3' '
+ git config --unset merge.conflictstyle
+ setup_conflicting_index &&
+ echo "none of the above" >sample &&
+ echo ourside >expect &&
+ cat sample >fild &&
+ cat sample >file &&
+ cat sample >filf &&
+ git checkout --conflict=diff3 -- fild file filf &&
+ (
+ echo "<<<<<<< ours"
+ echo ourside
+ echo "|||||||"
+ echo original
+ echo "======="
+ echo theirside
+ echo ">>>>>>> theirs"
+ ) >merged &&
+ test_cmp expect fild &&
+ test_cmp expect filf &&
+ test_cmp merged file
+'
+
test_done