diffy icon indicating copy to clipboard operation
diffy copied to clipboard

Add the ability to set the filename's used for `create_patch` and `merge`

Open bmwill opened this issue 5 years ago • 3 comments

Right now users are unable to set their own filenames, which appear when displaying a patch or when a merge has conflicts. There should be some interface which makes it easy for user's to overwrite the currently used defaults. A few options include:

  1. Adding the ability to set the names via an option in DiffOptions and MergeOptions
  2. Introduce a new thin wrapper File which is a tuple (filename, contents) which are passed into the create_patch and merge methods instead of just passing in their contents.

bmwill avatar Jul 01 '20 19:07 bmwill

I was looking at implementing this because I'd like it in guppy, and I'm wondering whether we need to treat filenames slightly differently than we do not. I did some investigation and it looks like git diff escapes filenames that aren't UTF-8. On Linux (tested on zsh):

git init
touch foobar$'\224'
git add .
git diff --cached

prints

diff --git "a/foobar\224" "b/foobar\224"
new file mode 100644
index 0000000..e69de29

Think maybe we should do the same thing, unless there's another use case I might be missing.

sunshowers avatar Dec 23 '20 01:12 sunshowers

Ah nvm:

git -c "core.quotePath=false" diff --cached

prints filenames without escaping them. Oh well.

sunshowers avatar Dec 23 '20 01:12 sunshowers

I was wondering the same, Patch::new does pretty much what I need but isn't public.

For other people running into this issue, there's a crate that can be used in the meantime: https://crates.io/crates/diffy-fork-filenames

kpcyrd avatar Apr 15 '24 23:04 kpcyrd