diff --git a/commands/command_clean.go b/commands/command_clean.go index 2be74b2f..314beee8 100644 --- a/commands/command_clean.go +++ b/commands/command_clean.go @@ -22,7 +22,7 @@ import ( // // If the object read from "from" is _already_ a clean pointer, then it will be // written out verbatim to "to", without trying to make it a pointer again. -func clean(to io.Writer, from io.Reader, fileName string, fileSize int64) error { +func clean(to io.Writer, from io.Reader, fileName string, fileSize int64) (*lfs.Pointer, error) { var cb progress.CopyCallback var file *os.File @@ -58,7 +58,7 @@ func clean(to io.Writer, from io.Reader, fileName string, fileSize int64) error // containing the bytes that we should write back out to Git. _, err = to.Write(errors.GetContext(err, "bytes").([]byte)) - return err + return nil, err } if err != nil { @@ -85,7 +85,7 @@ func clean(to io.Writer, from io.Reader, fileName string, fileSize int64) error } _, err = lfs.EncodePointer(to, cleaned.Pointer) - return err + return cleaned.Pointer, err } func cleanCommand(cmd *cobra.Command, args []string) { @@ -97,9 +97,14 @@ func cleanCommand(cmd *cobra.Command, args []string) { fileName = args[0] } - if err := clean(os.Stdout, os.Stdin, fileName, -1); err != nil { + ptr, err := clean(os.Stdout, os.Stdin, fileName, -1) + if err != nil { Error(err.Error()) } + + if ptr != nil && possiblyMalformedObjectSize(ptr.Size) { + Error("Possibly malformed conversion on Windows, see `git lfs help smudge` for more details.") + } } func init() { diff --git a/commands/command_filter_process.go b/commands/command_filter_process.go index 3edc5914..a2018c61 100644 --- a/commands/command_filter_process.go +++ b/commands/command_filter_process.go @@ -63,7 +63,13 @@ func filterCommand(cmd *cobra.Command, args []string) { switch req.Header["command"] { case "clean": w = git.NewPktlineWriter(os.Stdout, cleanFilterBufferCapacity) - err = clean(w, req.Payload, req.Header["pathname"], -1) + + var ptr *lfs.Pointer + ptr, err = clean(w, req.Payload, req.Header["pathname"], -1) + + if ptr != nil { + n = ptr.Size + } case "smudge": w = git.NewPktlineWriter(os.Stdout, smudgeFilterBufferCapacity) n, err = smudge(w, req.Payload, req.Header["pathname"], skip, filter) @@ -74,7 +80,7 @@ func filterCommand(cmd *cobra.Command, args []string) { if errors.IsNotAPointerError(err) { malformed = append(malformed, req.Header["pathname"]) err = nil - } else if possiblyMalformedSmudge(n) { + } else if possiblyMalformedObjectSize(n) { malformedOnWindows = append(malformedOnWindows, req.Header["pathname"]) } diff --git a/commands/command_migrate_import.go b/commands/command_migrate_import.go index 501f9eeb..6920c0ef 100644 --- a/commands/command_migrate_import.go +++ b/commands/command_migrate_import.go @@ -35,7 +35,7 @@ func migrateImportCommand(cmd *cobra.Command, args []string) { var buf bytes.Buffer - if err := clean(&buf, b.Contents, path, b.Size); err != nil { + if _, err := clean(&buf, b.Contents, path, b.Size); err != nil { return nil, err } diff --git a/commands/command_smudge.go b/commands/command_smudge.go index ffedc8b6..276e181f 100644 --- a/commands/command_smudge.go +++ b/commands/command_smudge.go @@ -101,7 +101,7 @@ func smudgeCommand(cmd *cobra.Command, args []string) { } else { Error(err.Error()) } - } else if possiblyMalformedSmudge(n) { + } else if possiblyMalformedObjectSize(n) { fmt.Fprintln(os.Stderr, "Possibly malformed smudge on Windows: see `git lfs help smudge` for more info.") } } @@ -113,7 +113,7 @@ func smudgeFilename(args []string) string { return "" } -func possiblyMalformedSmudge(n int64) bool { +func possiblyMalformedObjectSize(n int64) bool { return n > 4*humanize.Gigabyte }