Skip to content

Commit

Permalink
Fix git status parsing for renames
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Apr 28, 2020
1 parent 175601e commit 94c02a0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/config_test.go
Expand Up @@ -44,7 +44,7 @@ func TestAutoCommitCommitMessage(t *testing.T) {
},
{
name: "rename",
statusStr: "2 R. N... 100644 100644 100644 9d06c86ecba40e1c695e69b55a40843df6a79cef 9d06c86ecba40e1c695e69b55a40843df6a79cef R100 chezmoi_rename.go chezmoi.go\n",
statusStr: "2 R. N... 100644 100644 100644 9d06c86ecba40e1c695e69b55a40843df6a79cef 9d06c86ecba40e1c695e69b55a40843df6a79cef R100 chezmoi_rename.go\tchezmoi.go\n",
expectedMessage: "Rename chezmoi.go to chezmoi_rename.go\n",
},
{
Expand Down
2 changes: 1 addition & 1 deletion internal/git/status.go
Expand Up @@ -98,7 +98,7 @@ var (
`([0-9a-f]+) ` +
`([0-9a-f]+) ` +
`([CR])([0-9]+) ` +
`(.*?) (.*)` +
`(.*?)\t(.*)` +
`$`,
)
statusPorcelainV2ZUnmergedRegexp = regexp.MustCompile(`` +
Expand Down
24 changes: 23 additions & 1 deletion internal/git/status_test.go
Expand Up @@ -72,7 +72,7 @@ func TestParseStatusPorcelainV2(t *testing.T) {
},
{
name: "renamed",
outputStr: "2 R. N... 100644 100644 100644 9d06c86ecba40e1c695e69b55a40843df6a79cef 9d06c86ecba40e1c695e69b55a40843df6a79cef R100 chezmoi_rename.go chezmoi.go\n",
outputStr: "2 R. N... 100644 100644 100644 9d06c86ecba40e1c695e69b55a40843df6a79cef 9d06c86ecba40e1c695e69b55a40843df6a79cef R100 chezmoi_rename.go\tchezmoi.go\n",
expectedStatus: &Status{
RenamedOrCopied: []RenamedOrCopiedStatus{
{
Expand All @@ -92,6 +92,28 @@ func TestParseStatusPorcelainV2(t *testing.T) {
},
},
},
{
name: "renamed_2",
outputStr: "2 R. N... 100644 100644 100644 ddbd961d7e4db2bb6615a9e8ce86364fa65e732d ddbd961d7e4db2bb6615a9e8ce86364fa65e732d R100 dot_config/chezmoi/private_chezmoi.toml\tdot_config/chezmoi/chezmoi.toml",
expectedStatus: &Status{
RenamedOrCopied: []RenamedOrCopiedStatus{
{
X: 82,
Y: 46,
Sub: "N...",
MH: 0o100644,
MI: 0o100644,
MW: 0o100644,
HH: "ddbd961d7e4db2bb6615a9e8ce86364fa65e732d",
HI: "ddbd961d7e4db2bb6615a9e8ce86364fa65e732d",
RC: 'R',
Score: 100,
Path: "dot_config/chezmoi/private_chezmoi.toml",
OrigPath: "dot_config/chezmoi/chezmoi.toml",
},
},
},
},
{
name: "modified_2",
outputStr: "1 .M N... 100644 100644 100644 5716ca5987cbf97d6bb54920bea6adde242d87e6 5716ca5987cbf97d6bb54920bea6adde242d87e6 foo\n",
Expand Down

0 comments on commit 94c02a0

Please sign in to comment.