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

5 messages from 2008-10-19 to 2008-10-20. Participants: Matt McCutchen, Junio C Hamano, Johannes Schindelin.
Thread: https://gitlist.dev/t/15958

## Matt McCutchen, 2008-10-19 00:54

Subject: "git checkout: --track and --no-track require -b" check accidentally resurrected?
Message-ID: <1224377652.19061.12.camel@mattlaptop2.local>
URL: https://gitlist.dev/e/1224377652.19061.12.camel%40mattlaptop2.local

```
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, 2008-10-19 22:15

Subject: Re: "git checkout: --track and --no-track require -b" check accidentally resurrected?
Message-ID: <7vhc785izq.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vhc785izq.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <1224377652.19061.12.camel@mattlaptop2.local>

```
Matt McCutchen <matt@mattmccutchen.net> writes:

> 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, 2008-10-19 22:52

Subject: Is XDL_MERGE_ZEALOUS too zealous (or maybe not zealous enough)?
Message-ID: <7v3ais5hb3.fsf_-_@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7v3ais5hb3.fsf_-_%40gitster.siamese.dyndns.org
In-Reply-To: <7vhc785izq.fsf@gitster.siamese.dyndns.org>

```
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, 2008-10-20 03:42

Subject: Re: Is XDL_MERGE_ZEALOUS too zealous (or maybe not zealous enough)?
Message-ID: <1224474120.19785.3.camel@mattlaptop2.local>
URL: https://gitlist.dev/e/1224474120.19785.3.camel%40mattlaptop2.local
In-Reply-To: <7v3ais5hb3.fsf_-_@gitster.siamese.dyndns.org>

```
On Sun, 2008-10-19 at 15:52 -0700, Junio C Hamano wrote:
> 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, 2008-10-20 16:17

Subject: Re: Is XDL_MERGE_ZEALOUS too zealous (or maybe not zealous enough)?
Message-ID: <alpine.DEB.1.00.0810201809100.22125@pacific.mpi-cbg.de.mpi-cbg.de>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0810201809100.22125%40pacific.mpi-cbg.de.mpi-cbg.de
In-Reply-To: <7v3ais5hb3.fsf_-_@gitster.siamese.dyndns.org>

```
Hi,

On Sun, 19 Oct 2008, Junio C Hamano wrote:

> <<<<<<< 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"

```
