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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 5.4.1
- Fix: `mob next` now correctly handles filenames with spaces when determining the last modified file for the open command.

# 5.4.0
- Feature: Add shortcut for `mob start --create` as `mob start -c`.

Expand Down
14 changes: 12 additions & 2 deletions mob.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
)

const (
versionNumber = "5.4.0"
versionNumber = "5.4.1"
minimumGitVersion = "2.13.0"
)

Expand Down Expand Up @@ -881,7 +881,17 @@ func getPathOfLastModifiedFile() string {
}

for _, file := range files {
absoluteFilepath := rootDir + "/" + file
unquotedFile := file
if strings.HasPrefix(file, "\"") {
var err error
unquotedFile, err = strconv.Unquote(file)
if err != nil {
say.Warning("Could not unquote filename from git: " + file)
say.Warning(err.Error())
continue
}
}
absoluteFilepath := rootDir + "/" + unquotedFile
say.Debug(absoluteFilepath)
info, err := os.Stat(absoluteFilepath)
if err != nil {
Expand Down
28 changes: 28 additions & 0 deletions mob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,19 @@ func TestStartNextStay_WriteLastModifiedFileInCommit_WhenFileIsModifiedAndWorkin
equals(t, silentgit("log", "--format=%B", "-n", "1", "HEAD"), configuration.WipCommitMessage+"\n\nlastFile:file1.txt")
}

func TestStartNextStay_WriteLastModifiedFileInCommit_WhenFilenameContainsSpaces(t *testing.T) {
_, configuration := setup(t)
configuration.NextStay = true
start(configuration)
createFile(t, "file with spaces.txt", "contentIrrelevant")
assertOnBranch(t, "mob-session")

next(configuration)

equals(t, silentgit("log", "--format=%B", "-n", "1", "HEAD"), configuration.WipCommitMessage+"\n\nlastFile:\"file with spaces.txt\"")
assertOnBranch(t, "mob-session")
}

func TestStartNextStay_DoNotWriteLastModifiedFileInCommit_WhenFileIsDeleted(t *testing.T) {
_, configuration := setup(t)
configuration.NextStay = true
Expand Down Expand Up @@ -2416,3 +2429,18 @@ func getSymlinkGitDirectory(path string) string {
func getSymlinkDirectory(path string) string {
return path + "/local-symlink"
}

func TestGetPathOfLastModifiedFile_HandlesFilenamesWithSpaces(t *testing.T) {
_, configuration := setup(t)
configuration.NextStay = true

start(configuration)
createFile(t, "file with spaces.txt", "content")

git("add", "--all")
lastFile := getPathOfLastModifiedFile()

if !strings.Contains(lastFile, "file with spaces.txt") {
t.Errorf("Expected lastFile to contain the spaced filename, got: %s", lastFile)
}
}
Loading