Skip to content

gohack undo leaves trailing newlines #68

@shihanng

Description

@shihanng

This is how we can reproduce the issue:

$ git clone https://github.com/rogpeppe/go-internal.git
$ gohack get gopkg.in/errgo.v2
$ gohack undo
$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   go.mod

no changes added to commit (use "git add" and/or "git commit -a")

git diff produces:

diff --git a/go.mod b/go.mod
index 1c11744..e980eb2 100644
--- a/go.mod
+++ b/go.mod
@@ -3,3 +3,5 @@ module github.com/rogpeppe/go-internal
 go 1.11

 require gopkg.in/errgo.v2 v2.1.0
+
+

What I expected is that it there should be no diff, i.e.

$ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

Looking at the Go's source code
https://github.com/golang/go/blob/26154f31ad6c801d8bad5ef58df1e9263c6beec7/src/cmd/go/internal/modcmd/edit.go#L209

maybe we could include modf.Cleanup() before modf.Format() in

func writeModFile(modf *modfile.File) error {

Created PR #69 for this. 😄

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions