Code

grep: NUL terminate input from a file
[git.git] / merge-recursive.c
index f55b7ebe11bbd54f00a84dd1eb9d34f60d74a1c3..cd3628c4d9b1831c73e752b3b49c9d88b9e23098 100644 (file)
@@ -3,6 +3,7 @@
  * Fredrik Kuivinen.
  * The thieves were Alex Riesen and Johannes Schindelin, in June/July 2006
  */
+#include "advice.h"
 #include "cache.h"
 #include "cache-tree.h"
 #include "commit.h"
@@ -170,18 +171,6 @@ static int git_merge_trees(int index_only,
        int rc;
        struct tree_desc t[3];
        struct unpack_trees_options opts;
-       static const struct unpack_trees_error_msgs msgs = {
-               /* would_overwrite */
-               "Your local changes to '%s' would be overwritten by merge.  Aborting.",
-               /* not_uptodate_file */
-               "Your local changes to '%s' would be overwritten by merge.  Aborting.",
-               /* not_uptodate_dir */
-               "Updating '%s' would lose untracked files in it.  Aborting.",
-               /* would_lose_untracked */
-               "Untracked working tree file '%s' would be %s by merge.  Aborting",
-               /* bind_overlap -- will not happen here */
-               NULL,
-       };
 
        memset(&opts, 0, sizeof(opts));
        if (index_only)
@@ -193,7 +182,7 @@ static int git_merge_trees(int index_only,
        opts.fn = threeway_merge;
        opts.src_index = &the_index;
        opts.dst_index = &the_index;
-       opts.msgs = msgs;
+       opts.msgs = get_porcelain_error_msgs();
 
        init_tree_desc_from_tree(t+0, common);
        init_tree_desc_from_tree(t+1, head);
@@ -1180,6 +1169,28 @@ static int process_entry(struct merge_options *o,
        return clean_merge;
 }
 
+struct unpack_trees_error_msgs get_porcelain_error_msgs(void)
+{
+       struct unpack_trees_error_msgs msgs = {
+               /* would_overwrite */
+               "Your local changes to '%s' would be overwritten by merge.  Aborting.",
+               /* not_uptodate_file */
+               "Your local changes to '%s' would be overwritten by merge.  Aborting.",
+               /* not_uptodate_dir */
+               "Updating '%s' would lose untracked files in it.  Aborting.",
+               /* would_lose_untracked */
+               "Untracked working tree file '%s' would be %s by merge.  Aborting",
+               /* bind_overlap -- will not happen here */
+               NULL,
+       };
+       if (advice_commit_before_merge) {
+               msgs.would_overwrite = msgs.not_uptodate_file =
+                       "Your local changes to '%s' would be overwritten by merge.  Aborting.\n"
+                       "Please, commit your changes or stash them before you can merge.";
+       }
+       return msgs;
+}
+
 int merge_trees(struct merge_options *o,
                struct tree *head,
                struct tree *merge,