Skip to contentSkip to conversation

mergetool feature request - select remote or local

DISCUSSION Caleb Cushing 3 participants 5 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

sometimes when merge-ing fast forward doesn't work. but you know what the resolution you want is.

example (current behavior)
Normal merge conflict for 'css/main.css':
{local}: modified
{remote}: modified
Hit return to start merge resolution tool (vimdiff):

but I don't want to. I know the remote updates are right. I could do a git checkout remotebranch filename but when you have 20 files that need updating this is annoying

my suggestion is this
Normal merge conflict for 'css/main.css':
{local}: modified
{remote}: modified
Use (l)local or (r)remote or (m)anual?

also in the event of having 20 files with this issue it would be nice to have an option after first starting mergetool for remote all or local all.

(note: I am not subscribed to the list)

Signature · 3 lines
Caleb Cushing

my blog http://xenoterracide.blogspot.com
#1 lore raw
Quoted 9 lines · Caleb Cushing

sometimes when merge-ing fast forward doesn't work. but you know what the resolution you want is.

example (current behavior)
Normal merge conflict for 'css/main.css':
{local}: modified
{remote}: modified
Hit return to start merge resolution tool (vimdiff):

Quoted 3 lines

but I don't want to. I know the remote updates are right. I could do a git checkout remotebranch filename but when you have 20 files that need updating this is annoying

I never understood why people are using git and not ftp when they say the other side is always right, but I see this comes up every once in a while, so it would probably be a good thing to support.

Quoted 5 lines

my suggestion is this
Normal merge conflict for 'css/main.css':
{local}: modified
{remote}: modified
Use (l)local or (r)remote or (m)anual?

The above "(l)local" and "(m)anual" look inconsistent, and the wording should be more like "local, remote or merge".

Quoted 2 lines

also in the event of having 20 files with this issue it would be nice to have an option after first starting mergetool for remote all or local all.

This makes me wonder if you are better off not using mergetool in such a situation. Instead, perhaps

	$ git ls-files -u --no-stage | xargs git checkout MERGE_HEAD

might be a better option? The attached is a completely untested weather-baloon patch.

If this turns out to be a better approach, perhaps we would further want to tweak things to make:

	$ git checkout --unmerged MERGE_HEAD [--] [<pathspec>...]

to work (if you want "local", you would use "HEAD" instead of "MERGE_HEAD").

I would have done so here if "git checkout" were still a scripted version, but now it is in C, it would take significantly more effort than it is worth just to raise a weatherbaloon.

 builtin-ls-files.c |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)
builtin-ls-files.c +22 -0
index dc7eab8..36b2875 100644
@@ -181,6 +181,8 @@ static void show_ce_entry(const char *tag, struct cache_entry *ce)
 {
 	int len = prefix_len;
 	int offset = prefix_offset;
+	static const char *last_tag_shown;
+	static struct cache_entry *last_ce_shown;
 
 	if (len >= ce_namelen(ce))
 		die("git-ls-files: internal error - cache entry not superset of prefix");
@@ -206,7 +208,18 @@ static void show_ce_entry(const char *tag, struct cache_entry *ce)
 	}
 
 	if (!show_stage) {
+		/*
+		 * Even when not showing stage information, we will call this
+		 * function for each stage.  Omit duplicate output.
+		 */
+		if ((!tag ||
+		     (last_tag_shown && !strcmp(last_tag_shown, tag))) &&
+		    (last_ce_shown &&
+		     !strcmp(last_ce_shown->name, ce->name)))
+			return;
 		fputs(tag, stdout);
+		last_tag_shown = tag;
+		last_ce_shown = ce;
 	} else {
 		printf("%s%06o %s %d\t",
 		       tag,
@@ -509,6 +522,15 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
 			show_unmerged = 1;
 			continue;
 		}
+		if (!strcmp(arg, "--no-stage")) {
+			/*
+			 * ... Not really.
+			 * Sometimes we would want a list of unmerged paths.
+			 */
+			show_stage = 0;
+			show_cached = 1;
+			continue;
+		}
 		if (!strcmp(arg, "-x") && i+1 < argc) {
 			exc_given = 1;
 			add_exclude(argv[++i], "", 0, &dir.exclude_list[EXC_CMDL]);
#2 lore raw
Quoted 3 lines · you

I never understood why people are using git and not ftp when they say the other side is always right, but I see this comes up every once in a while, so it would probably be a good thing to support.

well in my case I'm not particularly sure why fast forward didn't just merge them. Seems like I had resolved these changes in master previously. this problem is most annoying when I am resolving the same issues across multiple branches.

Quoted 2 lines

The above "(l)local" and "(m)anual" look inconsistent, and the wording should be more like "local, remote or merge".

local,remote, merge is fine and I used the (m) for example because of how it asked me to handle a file existing locally (with mods?) but had been deleted in MERGE_HEAD?

Quoted 8 lines
Quoted 3 lines

also in the event of having 20 files with this issue it would be nice to have an option after first starting mergetool for remote all or local all.

This makes me wonder if you are better off not using mergetool in such a situation.  Instead, perhaps

        $ git ls-files -u --no-stage | xargs git checkout MERGE_HEAD

perhaps... I'm not this familiar with git yet.

Quoted 6 lines

might be a better option?  The attached is a completely untested weather-baloon patch.

If this turns out to be a better approach, perhaps we would further want to tweak things to make:

Quoted 7 lines
        $ git checkout --unmerged MERGE_HEAD [--] [<pathspec>...]

to work (if you want "local", you would use "HEAD" instead of "MERGE_HEAD").

Looks easy enough. Caleb, does this approach fit the situation you described better?

um.. is that just a resolution for an merge all (local or remote).

I'm gonna be honest when I say I'm an amateur developer (although I've considered myself a pretty good admin for a few years) and relatively new to git. So I'm getting a bit lost, but it sounds reasonable. It wouldn't affect any files that had been successfully fast forwarded right?

unfortunately I'm not sure how easy testing will be, as this problem doesn't arise with every merge, but has arisen often enough to be a pita.

Signature · 3 lines
Caleb Cushing

my blog http://xenoterracide.blogspot.com
#3 lore raw
In reply to Junio C Hamano
Quoted 8 lines · Junio C Hamano

This makes me wonder if you are better off not using mergetool in such a situation. Instead, perhaps

	$ git ls-files -u --no-stage | xargs git checkout MERGE_HEAD

might be a better option? The attached is a completely untested weather-baloon patch.

Quoted 7 lines

If this turns out to be a better approach, perhaps we would further want to tweak things to make:

	$ git checkout --unmerged MERGE_HEAD [--] [<pathspec>...]

to work (if you want "local", you would use "HEAD" instead of "MERGE_HEAD").

This is "for all (or some, by pathspecs) files currently unmerged in the index, resolve them to the version in MERGE_HEAD", right?

Quoted 3 lines

I would have done so here if "git checkout" were still a scripted version, but now it is in C, it would take significantly more effort than it is worth just to raise a weatherbaloon.

Like this (also untested)? (This is missing defaulting to a pathspec of '.' if --unmerged is used without any pathspecs)

builtin-checkout.c +10 -0
index 10ec137..0bae1d4 100644
@@ -42,6 +42,8 @@ static int post_checkout_hook(struct commit *old, struct commit *new,
 	return run_command(&proc);
 }
 
+static int unmerged;
+
 static int update_some(const unsigned char *sha1, const char *base, int baselen,
 		       const char *pathname, unsigned mode, int stage)
 {
@@ -59,6 +61,13 @@ static int update_some(const unsigned char *sha1, const char *base, int baselen,
 	hashcpy(ce->sha1, sha1);
 	memcpy(ce->name, base, baselen);
 	memcpy(ce->name + baselen, pathname, len - baselen);
+	if (unmerged) {
+		int pos = cache_name_pos(ce->name, len);
+		if (!(pos && pos < active_nr && ce_same_name(active_cache[pos], active_cache[pos + 1]))) {
+			free(ce);
+			return 0;
+		}
+	}
 	ce->ce_flags = create_ce_flags(len, 0);
 	ce->ce_mode = create_ce_mode(mode);
 	add_cache_entry(ce, ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);
@@ -508,6 +517,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
 			BRANCH_TRACK_EXPLICIT),
 		OPT_BOOLEAN('f', NULL, &opts.force, "force"),
 		OPT_BOOLEAN('m', NULL, &opts.merge, "merge"),
+		OPT_BOOLEAN( 0 , "unmerged", &unmerged, "check out unmerged paths"),
 		OPT_END(),
 	};
 
#4 lore raw
Quoted 5 lines · Daniel Barkalow

On Wed, 14 May 2008, Junio C Hamano wrote:
...

Quoted 3 lines

If this turns out to be a better approach, perhaps we would further want to tweak things to make:

Quoted 7 lines
Quoted 4 lines
	$ git checkout --unmerged MERGE_HEAD [--] [<pathspec>...]

to work (if you want "local", you would use "HEAD" instead of "MERGE_HEAD").

This is "for all (or some, by pathspecs) files currently unmerged in the index, resolve them to the version in MERGE_HEAD", right?

Yeah, and possibly limited by pathspec as usual.

Quoted 6 lines
Quoted 3 lines

I would have done so here if "git checkout" were still a scripted version, but now it is in C, it would take significantly more effort than it is worth just to raise a weatherbaloon.

Like this (also untested)? (This is missing defaulting to a pathspec of '.' if --unmerged is used without any pathspecs)

Looks easy enough. Caleb, does this approach fit the situation you described better?

Quoted 35 lines
builtin-checkout.c +10 -0
index 10ec137..0bae1d4 100644
@@ -42,6 +42,8 @@ static int post_checkout_hook(struct commit *old, struct commit *new,
 	return run_command(&proc);
 }
 
+static int unmerged;
+
 static int update_some(const unsigned char *sha1, const char *base, int baselen,
 		       const char *pathname, unsigned mode, int stage)
 {
@@ -59,6 +61,13 @@ static int update_some(const unsigned char *sha1, const char *base, int baselen,
 	hashcpy(ce->sha1, sha1);
 	memcpy(ce->name, base, baselen);
 	memcpy(ce->name + baselen, pathname, len - baselen);
+	if (unmerged) {
+		int pos = cache_name_pos(ce->name, len);
+		if (!(pos && pos < active_nr && ce_same_name(active_cache[pos], active_cache[pos + 1]))) {
+			free(ce);
+			return 0;
+		}
+	}
 	ce->ce_flags = create_ce_flags(len, 0);
 	ce->ce_mode = create_ce_mode(mode);
 	add_cache_entry(ce, ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);
@@ -508,6 +517,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
 			BRANCH_TRACK_EXPLICIT),
 		OPT_BOOLEAN('f', NULL, &opts.force, "force"),
 		OPT_BOOLEAN('m', NULL, &opts.merge, "merge"),
+		OPT_BOOLEAN( 0 , "unmerged", &unmerged, "check out unmerged paths"),
 		OPT_END(),
 	};