8
#include "progress.h"
9
#include "refs.h"
10
11
+/*
12
+ * Error messages expected by scripts out of plumbing commands such as
13
+ * read-tree. Non-scripted Porcelain is not required to use these messages
14
+ * and in fact are encouraged to reword them to better suit their particular
15
+ * situation better. See how "git checkout" replaces not_uptodate_file to
16
+ * explain why it does not allow switching between branches when you have
17
+ * local changes, for example.
18
+ */
19
+static struct unpack_trees_error_msgs unpack_plumbing_errors = {
20
+ /* would_overwrite */
21
+ "Entry '%s' would be overwritten by merge. Cannot merge.",
22
+
23
+ /* not_uptodate_file */
24
+ "Entry '%s' not uptodate. Cannot merge.",
25
+
26
+ /* not_uptodate_dir */
27
+ "Updating '%s' would lose untracked files in it",
28
+
29
+ /* would_lose_untracked */
30
+ "Untracked working tree file '%s' would be %s by merge.",
31
+
32
+ /* bind_overlap */
33
+ "Entry '%s' overlaps with '%s'. Cannot bind.",
34
+};
35
+
36
+#define ERRORMSG(o,fld) \
37
+ ( ((o) && (o)->msgs.fld) \
38
+ ? ((o)->msgs.fld) \
39
+ : (unpack_plumbing_errors.fld) )
40
+
41
static void add_entry(struct unpack_trees_options *o, struct cache_entry *ce,
42
unsigned int set, unsigned int clear)
43
{
413
414
/* Here come the merge functions */
415
386
-static int reject_merge(struct cache_entry *ce)
416
+static int reject_merge(struct cache_entry *ce, struct unpack_trees_options *o)
417
{
388
- return error("Entry '%s' would be overwritten by merge. Cannot merge.",
389
- ce->name);
418
+ return error(ERRORMSG(o, would_overwrite), ce->name);
419
}
420
421
static int same(struct cache_entry *a, struct cache_entry *b)
459
if (errno == ENOENT)
460
return 0;
461
return o->gently ? -1 :
433
- error("Entry '%s' not uptodate. Cannot merge.", ce->name);
462
+ error(ERRORMSG(o, not_uptodate_file), ce->name);
463
}
464
465
static void invalidate_ce_path(struct cache_entry *ce, struct unpack_trees_options *o)
546
i = read_directory(&d, ce->name, pathbuf, namelen+1, NULL);
547
if (i)
548
return o->gently ? -1 :
520
- error("Updating '%s' would lose untracked files in it",
521
- ce->name);
549
+ error(ERRORMSG(o, not_uptodate_dir), ce->name);
550
free(pathbuf);
551
return cnt;
552
}
646
}
647
648
return o->gently ? -1 :
621
- error("Untracked working tree file '%s' "
622
- "would be %s by merge.", ce->name, action);
649
+ error(ERRORMSG(o, would_lose_untracked), ce->name, action);
650
}
651
return 0;
652
}
778
/* #14, #14ALT, #2ALT */
779
if (remote && !df_conflict_head && head_match && !remote_match) {
780
if (index && !same(index, remote) && !same(index, head))
754
- return o->gently ? -1 : reject_merge(index);
781
+ return o->gently ? -1 : reject_merge(index, o);
782
return merged_entry(remote, index, o);
783
}
784
/*
786
* make sure that it matches head.
787
*/
788
if (index && !same(index, head))
762
- return o->gently ? -1 : reject_merge(index);
789
+ return o->gently ? -1 : reject_merge(index, o);
790
791
if (head) {
792
/* #5ALT, #15 */
928
else {
929
/* all other failures */
930
if (oldtree)
904
- return o->gently ? -1 : reject_merge(oldtree);
931
+ return o->gently ? -1 : reject_merge(oldtree, o);
932
if (current)
906
- return o->gently ? -1 : reject_merge(current);
933
+ return o->gently ? -1 : reject_merge(current, o);
934
if (newtree)
908
- return o->gently ? -1 : reject_merge(newtree);
935
+ return o->gently ? -1 : reject_merge(newtree, o);
936
return -1;
937
}
938
}
958
o->merge_size);
959
if (a && old)
960
return o->gently ? -1 :
934
- error("Entry '%s' overlaps with '%s'. Cannot bind.", a->name, old->name);
961
+ error(ERRORMSG(o, bind_overlap), a->name, old->name);
962
if (!a)
963
return keep_entry(old, o);
964
else