Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions backend/utils/tw/edit_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,14 @@ func EditTaskInTaskwarrior(uuid, description, email, encryptionSecret, taskID st
}

// Handle depends - always set to ensure clearing works
dependsStr := strings.Join(depends, ",")
if err := utils.ExecCommand("task", taskID, "modify", "depends:"+dependsStr); err != nil {
return fmt.Errorf("failed to set depends %s: %v", dependsStr, err)
if err := utils.ExecCommand("task", taskID, "modify", "depends:"); err != nil {
return fmt.Errorf("failed to clear dependencies: %v", err)
}
if len(depends) > 0 {
dependsStr := strings.Join(depends, ",")
if err := utils.ExecCommand("task", taskID, "modify", "depends:"+dependsStr); err != nil {
return fmt.Errorf("failed to set dependencies %s: %v", dependsStr, err)
}
}

// Handle due date
Expand Down
11 changes: 8 additions & 3 deletions backend/utils/tw/modify_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,14 @@ func ModifyTaskInTaskwarrior(uuid, description, project, priority, status, due,
}

// Handle dependencies - always set to ensure clearing works
dependsStr := strings.Join(depends, ",")
if err := utils.ExecCommand("task", taskID, "modify", "depends:"+dependsStr); err != nil {
return fmt.Errorf("failed to set dependencies %s: %v", dependsStr, err)
if err := utils.ExecCommand("task", taskID, "modify", "depends:"); err != nil {
return fmt.Errorf("failed to clear dependencies: %v", err)
}
if len(depends) > 0 {
dependsStr := strings.Join(depends, ",")
if err := utils.ExecCommand("task", taskID, "modify", "depends:"+dependsStr); err != nil {
return fmt.Errorf("failed to set dependencies %s: %v", dependsStr, err)
}
}

// escapedStatus := fmt.Sprintf(`status:%s`, strings.ReplaceAll(status, `"`, `\"`))
Expand Down
71 changes: 71 additions & 0 deletions backend/utils/tw/taskwarrior_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,74 @@ func TestModifyTaskWithTags(t *testing.T) {
fmt.Println("Modify task with tags passed")
}
}

func TestRemoveDependencyFromMultipleDependencies(t *testing.T) {
taskID := "taskuuid"
email := "email"
secret := "encryptionSecret"
uuid := "uuid"
initialDeps := []string{"uuid-1", "uuid-2", "uuid-3"}
updatedDeps := []string{"uuid-1", "uuid-3"}

err := ModifyTaskInTaskwarrior(
uuid,
"Test Task",
"project",
"H",
"pending",
"2025-03-03",
email,
secret,
taskID,
[]string{},
initialDeps,
)
if err != nil {
t.Fatalf("failed to set initial dependencies: %v", err)
}

err = ModifyTaskInTaskwarrior(
uuid,
"Test Task",
"project",
"H",
"pending",
"2025-03-03",
email,
secret,
taskID,
[]string{},
updatedDeps,
)
if err != nil {
t.Fatalf("failed to update dependencies: %v", err)
}
tasks, err := ExportTasks("./")
if err != nil {
t.Fatalf("failed to export tasks: %v", err)
}
var found bool
expected := map[string]bool{
"uuid-1": true,
"uuid-3": true,
}

for _, task := range tasks {
if task.UUID == taskID {
found = true

if len(task.Depends) != len(updatedDeps) {
t.Fatalf("expected %d dependencies, got %d", len(updatedDeps), len(task.Depends))
}

for _, d := range task.Depends {
if !expected[d] {
t.Fatalf("unexpected dependency found: %s", d)
}
}
}
}
if !found {
t.Fatalf("task %s not found in export", taskID)
}
}
Loading