threads / discuss / 15958

"git checkout: --track and --no-track require -b" check accidentally resurrected?

Subject: "git checkout: --track and --no-track require -b" check accidentally resurrected?

## tl;dr

5 messages between Oct 19, 2008 and Oct 20, 2008.

replies: 4people: 3as markdown or json

Matt McCutchen· Oct 19, 2008, 00:54 UTC · lore

Merge commit 9ba929ed resurrected the following two-line check, which was removed in the first parent and unchanged in the second:

	if (!opts.new_branch && (opts.track != git_branch_track))
		die("git checkout: --track and --no-track require -b");
Is this intentional?  Does it make a difference?

(I noticed this while carefully examining 9ba929ed to find out why "git merge" stopped honoring merge.conflictstyle. Ironically, I hit this bug again during the examination.)

Matt
Junio C Hamano· Oct 19, 2008, 22:15 UTC · re: Matt McCutchen · lore

Re: "git checkout: --track and --no-track require -b" check accidentally resurrected?

Matt McCutchen <matt@mattmccutchen.net> writes:
Show 11 quoted lines
> Merge commit 9ba929ed resurrected the following two-line check, which
> was removed in the first parent and unchanged in the second:
>
> 	if (!opts.new_branch && (opts.track != git_branch_track))
> 		die("git checkout: --track and --no-track require -b");
>
> Is this intentional?  Does it make a difference?
>
> (I noticed this while carefully examining 9ba929ed to find out why "git
> merge" stopped honoring merge.conflictstyle.  Ironically, I hit this bug
> again during the examination.)

Again, good eyes. I think the two lines should go; my fault at cdb22c4 (Merge branch 'jc/better-conflict-resolution' into next, 2008-09-02).

Thanks.
Junio C Hamano· Oct 19, 2008, 22:52 UTC · re: Junio C Hamano · lore

Is XDL_MERGE_ZEALOUS too zealous (or maybe not zealous enough)?

Junio C Hamano <gitster@pobox.com> writes:
> Again, good eyes.  I think the two lines should go; my fault at cdb22c4
> (Merge branch 'jc/better-conflict-resolution' into next, 2008-09-02).
Hmm, I am somewhat unhappy.  If you run:
	$ git checkout cdb22c4^
        $ git merge cdb22c4^2
	$ git checkout --conflict=diff3 builtin-checkout.c
and look at builtin-checkout.c.  You will find this:
<<<<<<< ours
	/* --track without -b should DWIM */
	if (0 < opts.track && !opts.new_branch) {
		const char *argv0 = argv[0];
	...
		opts.new_branch = argv0 + 1;
	}
	if (opts.track == BRANCH_TRACK_UNSPECIFIED)
		opts.track = git_branch_track;
|||||||
	if (!opts.new_branch && (opts.track != git_branch_track))
		die("git checkout: --track and --no-track require -b");
=======
	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");
>>>>>>> theirs

The two lines in the middle was from the common ancestor, which was not touched by the merged branch (that added the "if (conflict_style) {}" block) and was lost by a rewrite in "ours".

However, the usual simplified merge shows this (run "git checkout --merge builtin-checkout.c" if you have done the above):

<<<<<<< ours
	/* --track without -b should DWIM */
	if (0 < opts.track && !opts.new_branch) {
		const char *argv0 = argv[0];
	...
		opts.new_branch = argv0 + 1;
	}
	if (opts.track == BRANCH_TRACK_UNSPECIFIED)
		opts.track = git_branch_track;
=======
	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");
>>>>>>> theirs

Removing the two lines from the simplified "theirs" is not what I would suggest (it would be actively wrong), but I wonder if we can do something clever to help users with a merge like this.

Matt McCutchen· Oct 20, 2008, 03:42 UTC · re: Junio C Hamano · lore

Re: Is XDL_MERGE_ZEALOUS too zealous (or maybe not zealous enough)?

On Sun, 2008-10-19 at 15:52 -0700, Junio C Hamano wrote:
Show 26 quoted lines
> However, the usual simplified merge shows this (run "git checkout --merge
> builtin-checkout.c" if you have done the above):
> 
> <<<<<<< ours
> 	/* --track without -b should DWIM */
> 	if (0 < opts.track && !opts.new_branch) {
> 		const char *argv0 = argv[0];
> 	...
> 		opts.new_branch = argv0 + 1;
> 	}
> 
> 	if (opts.track == BRANCH_TRACK_UNSPECIFIED)
> 		opts.track = git_branch_track;
> =======
> 	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");
> >>>>>>> theirs
> 
> Removing the two lines from the simplified "theirs" is not what I would
> suggest (it would be actively wrong), but I wonder if we can do something
> clever to help users with a merge like this.

IMHO, the solution is just to use diff3 style. I never understood how I was supposed to intuit the correct result of a merge from the two sides without seeing the common ancestor, so I am glad to have the diff3 style working now.

Matt
Johannes Schindelin· Oct 20, 2008, 16:17 UTC · re: Junio C Hamano · lore

Re: Is XDL_MERGE_ZEALOUS too zealous (or maybe not zealous enough)?

Hi,
On Sun, 19 Oct 2008, Junio C Hamano wrote:
Show 19 quoted lines
> <<<<<<< ours
> 	/* --track without -b should DWIM */
> 	if (0 < opts.track && !opts.new_branch) {
> 		const char *argv0 = argv[0];
> 	...
> 		opts.new_branch = argv0 + 1;
> 	}
> 
> 	if (opts.track == BRANCH_TRACK_UNSPECIFIED)
> 		opts.track = git_branch_track;
> =======
> 	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");
> >>>>>>> theirs

This is that case that adjacent blocks A and B are changed to A' B and A B' in the to-be-merged branches.

I could imagine that you would have this automerged to A' B', but I actually advise against that.

My gut feeling tells me that a "for" statement as block "A" and some change ("B") in the _body_ of the "for" loop that takes advantage of the original version of the "for" statement would be _real_ hard to detect.

Better have trivial conflicts reported, but catch more non-trivial ones (instead of mismerging them).

(Another possibility would be that block "B" is actually an "else". Also in this case it is easy to think of cases that would wreak havoc; OTOH we would mismerge them _already_ if at least 1 common line is unchanged between the blocks. Tough.)

But I might be completely wrong.

Ciao, Dscho "who is a little jet-lagged, so you should trust him even less than normally"

← back to recent threads