Merge branch 'ew/empty-merge-with-dirty-index-maint' into ew/empty-merge-with-dirty-index
authorJunio C Hamano <gitster@pobox.com>
Fri, 22 Dec 2017 20:48:38 +0000 (12:48 -0800)
committerJunio C Hamano <gitster@pobox.com>
Fri, 22 Dec 2017 20:48:38 +0000 (12:48 -0800)
* ew/empty-merge-with-dirty-index-maint:
merge-recursive: avoid incorporating uncommitted changes in a merge
move index_has_changes() from builtin/am.c to merge.c for reuse
t6044: recursive can silently incorporate dirty changes in a merge

1  2 
builtin/am.c
cache.h
merge-recursive.c
merge.c
diff --cc builtin/am.c
Simple merge
diff --cc cache.h
Simple merge
Simple merge
diff --cc merge.c
index e5d796c9f2d110bdcd378b361fe2052ac1dcc266,b0714bc85ec1b75ffb2eea1a00f20debae4df706..195b5787005ee8f63bc10845f6d788aa4730a61b
+++ b/merge.c
@@@ -15,6 -17,37 +17,37 @@@ static const char *merge_argument(struc
                return EMPTY_TREE_SHA1_HEX;
  }
  
 -              DIFF_OPT_SET(&opt, EXIT_WITH_STATUS);
+ int index_has_changes(struct strbuf *sb)
+ {
+       struct object_id head;
+       int i;
+       if (!get_oid_tree("HEAD", &head)) {
+               struct diff_options opt;
+               diff_setup(&opt);
 -                      DIFF_OPT_SET(&opt, QUICK);
++              opt.flags.exit_with_status = 1;
+               if (!sb)
 -              return DIFF_OPT_TST(&opt, HAS_CHANGES) != 0;
++                      opt.flags.quick = 1;
+               do_diff_cache(&head, &opt);
+               diffcore_std(&opt);
+               for (i = 0; sb && i < diff_queued_diff.nr; i++) {
+                       if (i)
+                               strbuf_addch(sb, ' ');
+                       strbuf_addstr(sb, diff_queued_diff.queue[i]->two->path);
+               }
+               diff_flush(&opt);
++              return opt.flags.has_changes != 0;
+       } else {
+               for (i = 0; sb && i < active_nr; i++) {
+                       if (i)
+                               strbuf_addch(sb, ' ');
+                       strbuf_addstr(sb, active_cache[i]->name);
+               }
+               return !!active_nr;
+       }
+ }
  int try_merge_command(const char *strategy, size_t xopts_nr,
                      const char **xopts, struct commit_list *common,
                      const char *head_arg, struct commit_list *remotes)