Skip to content

Commit 3c3f1cf

Browse files
committed
cmd/go: fix formatting of file paths under cwd
The output of go with -x flag is formatted in a manner that file paths under current directory are modified to start with a dot (.), but when the directory path ends with a slash (/), the formatting goes wrong. Fixes 23982.
1 parent 16c5d30 commit 3c3f1cf

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/cmd/go/internal/work/exec.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,11 @@ func mayberemovefile(s string) {
13641364
func (b *Builder) fmtcmd(dir string, format string, args ...interface{}) string {
13651365
cmd := fmt.Sprintf(format, args...)
13661366
if dir != "" && dir != "/" {
1367-
cmd = strings.Replace(" "+cmd, " "+dir, " .", -1)[1:]
1367+
dot := " ."
1368+
if dir[len(dir)-1] == '/' {
1369+
dot += "/"
1370+
}
1371+
cmd = strings.Replace(" "+cmd, " "+dir, dot, -1)[1:]
13681372
if b.scriptDir != dir {
13691373
b.scriptDir = dir
13701374
cmd = "cd " + dir + "\n" + cmd

0 commit comments

Comments
 (0)