Skip to content

Commit 7ee599a

Browse files
authored
Merge pull request #229 from niklaas/fix/note-non-tty
Fix note <id> <text> discarding text without a TTY
2 parents 9a620e6 + 10efb49 commit 7ee599a

5 files changed

Lines changed: 58 additions & 29 deletions

File tree

.github/workflows/ci.yml

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,14 @@ jobs:
3636
with:
3737
go-version-file: go.mod
3838

39-
- name: Go mod vendor
40-
run: go mod vendor
41-
4239
- name: Configure Git User
4340
run: |
4441
git config --global user.name "GitHub Actions Bot"
4542
git config --global user.email "actions@github.com"
4643
4744
- name: Run tests
4845
run: |
49-
go test -v -mod=vendor ./...
46+
go test -v ./...
5047
./integrationtest.sh
5148
5249
windows-test:
@@ -63,10 +60,6 @@ jobs:
6360
with:
6461
go-version-file: go.mod
6562

66-
- name: Go mod vendor
67-
shell: pwsh
68-
run: go mod vendor
69-
7063
- name: Configure Git User
7164
shell: pwsh
7265
run: |
@@ -75,10 +68,10 @@ jobs:
7568
7669
- name: Run Go tests
7770
shell: pwsh
78-
run: go test -v -mod=vendor ./...
71+
run: go test -v ./...
7972

8073
- name: Build Windows binaries
8174
shell: pwsh
8275
run: |
83-
go build -mod=vendor -o dstask.exe ./cmd/dstask
84-
go build -mod=vendor -o dstask-import.exe ./cmd/dstask-import
76+
go build -o dstask.exe ./cmd/dstask
77+
go build -o dstask-import.exe ./cmd/dstask-import

commands.go

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -304,28 +304,26 @@ func CommandNote(conf Config, ctx, query Query) error {
304304

305305
for _, id := range query.IDs {
306306
task := ts.MustGetByID(id)
307-
// If stdout is a TTY, we may open the editor
308-
if StdoutIsTTY() {
309-
if query.Text == "" {
310-
task.Notes = string(
311-
MustEditBytes(
312-
[]byte(task.Notes),
313-
MakeTempFilename(task.ID, task.Summary, "md"),
314-
),
315-
)
307+
if query.Text != "" {
308+
if task.Notes == "" {
309+
task.Notes = query.Text
316310
} else {
317-
if task.Notes == "" {
318-
task.Notes = query.Text
319-
} else {
320-
task.Notes += "\n" + query.Text
321-
}
311+
task.Notes += "\n" + query.Text
322312
}
323-
313+
ts.MustUpdateTask(task)
314+
ts.SavePendingChanges()
315+
MustGitCommit(conf.Repo, "Edit note %s", task)
316+
} else if StdoutIsTTY() {
317+
task.Notes = string(
318+
MustEditBytes(
319+
[]byte(task.Notes),
320+
MakeTempFilename(task.ID, task.Summary, "md"),
321+
),
322+
)
324323
ts.MustUpdateTask(task)
325324
ts.SavePendingChanges()
326325
MustGitCommit(conf.Repo, "Edit note %s", task)
327326
} else {
328-
// If stdout is not a TTY, we simply write markdown notes to stdout
329327
if err := WriteStdout([]byte(task.Notes)); err != nil {
330328
ExitFail("Could not write to stdout: %v", err)
331329
}

integration/main_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestMain(m *testing.M) {
3535
func compile(outputPath string) error {
3636
// We expect to execute in the ./integration directory, and we will output
3737
// our test binary there.
38-
cmd := exec.Command("go", "build", "-mod=vendor", "-o", outputPath, "../cmd/dstask/main.go")
38+
cmd := exec.Command("go", "build", "-o", outputPath, "../cmd/dstask/main.go")
3939

4040
return cmd.Run()
4141
}

integration/note_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package integration
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
"github.com/stretchr/testify/require"
8+
)
9+
10+
func TestNoteAppendTextWithoutTTY(t *testing.T) {
11+
repo, cleanup := makeDstaskRepo(t)
12+
defer cleanup()
13+
14+
program := testCmd(repo)
15+
16+
output, exiterr, success := program("add", "test task")
17+
assertProgramResult(t, output, exiterr, success)
18+
19+
_, exiterr, success = program("note", "1", "first line")
20+
assertProgramResult(t, nil, exiterr, success)
21+
22+
output, exiterr, success = program("show-open")
23+
assertProgramResult(t, output, exiterr, success)
24+
25+
tasks := unmarshalTaskArray(t, output)
26+
require.Len(t, tasks, 1)
27+
assert.Equal(t, "first line", tasks[0].Notes)
28+
29+
_, exiterr, success = program("note", "1", "second line")
30+
assertProgramResult(t, nil, exiterr, success)
31+
32+
output, exiterr, success = program("show-open")
33+
assertProgramResult(t, output, exiterr, success)
34+
35+
tasks = unmarshalTaskArray(t, output)
36+
require.Len(t, tasks, 1)
37+
assert.Equal(t, "first line\nsecond line", tasks[0].Notes)
38+
}

integrationtest.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ cleanup() {
2828

2929
trap cleanup EXIT
3030

31-
go build -o dstask -mod=vendor cmd/dstask/main.go
31+
go build -o dstask cmd/dstask/main.go
3232

3333
# initialse git repo
3434
git -C $DSTASK_GIT_REPO init

0 commit comments

Comments
 (0)