When merging tasks, remove duplicate project and context tags
1 files changed, 24 insertions(+), 8 deletions(-)

M main.go
M main.go +24 -8
@@ 127,21 127,37 @@ func merge(a, b todotxt.Task) todotxt.Ta
 	t.Completed = b.Completed || a.Completed
 	sort.Strings(a.Projects)
 	sort.Strings(b.Projects)
-	t.Projects = make([]string, len(a.Projects))
-	for i, ap := range a.Projects {
-		t.Projects[i] = ap
+	t.Projects = make([]string, 0, len(a.Projects))
+	// Remove duplicate project tags
+	prjcts := make(map[string]bool)
+	for _, ap := range a.Projects {
+		if !prjcts[ap] {
+			t.Projects = append(t.Projects, ap)
+			prjcts[ap] = true
+		}
 	}
 	for _, bp := range b.Projects {
-		t.Projects = append(t.Projects, bp)
+		if !prjcts[bp] {
+			t.Projects = append(t.Projects, bp)
+			prjcts[bp] = true
+		}
 	}
 	sort.Strings(a.Contexts)
 	sort.Strings(b.Contexts)
-	t.Contexts = make([]string, len(a.Contexts))
-	for i, ap := range a.Contexts {
-		t.Contexts[i] = ap
+	t.Contexts = make([]string, 0, len(a.Contexts))
+	// Remove duplicate context tags
+	ctxts := make(map[string]bool)
+	for _, ap := range a.Contexts {
+		if !ctxts[ap] {
+			t.Contexts = append(t.Contexts, ap)
+			ctxts[ap] = true
+		}
 	}
 	for _, bp := range b.Contexts {
-		t.Contexts = append(t.Contexts, bp)
+		if !ctxts[bp] {
+			t.Contexts = append(t.Contexts, bp)
+			ctxts[bp] = true
+		}
 	}
 	t.AdditionalTags = make(map[string]string)
 	for k, v := range a.AdditionalTags {