diffsitter icon indicating copy to clipboard operation
diffsitter copied to clipboard

Add example usage with git difftool.

Open ClashTheBunny opened this issue 3 years ago • 8 comments

Shamelessly stolen from: https://github.com/wilfred/difftastic#dogfooding

ClashTheBunny avatar Jul 19 '21 23:07 ClashTheBunny

Here's an example with https://github.com/hrkfdn/ncspot/ adding a non-semantic diff:

 randall@penguin  ~/c/ncspot   master ⁝ ✱ ? 
 ❯ git difftool                                                                 [21:16:37]
/tmp/randall/LS3cZU_main.rs -> src/main.rs
==========================================

 randall@penguin  ~/c/ncspot   master ⁝ ✱ ? 
 ❯ git diff                                                                     [21:16:40]
diff --git i/src/main.rs w/src/main.rs
index d658e89..0de8190 100644
--- i/src/main.rs
+++ w/src/main.rs
@@ -174,8 +174,11 @@ fn main() {
     let mut credentials = {
         let cached_credentials = cache.credentials();
         match cached_credentials {
+
             Some(c) => {
-                info!("Using cached credentials");
+                info!(
+                    "Using cached credentials"
+                    );
                 c
             }
             None => credentials_prompt(None),

And another one with a rename:

 randall@penguin  ~/c/ncspot   master ⁝ ✱ ? 
 ❯ git difftool                                                                 [21:19:16]
/tmp/randall/h2FgKg_main.rs -> src/main.rs
==========================================

174 - 175:
----------
-         let cached_credentials = cache.credentials();
-         match cached_credentials {

174 - 175:
----------
+         let cached_credential = cache.credentials();
+         match cached_credential {

 randall@penguin  ~/c/ncspot   master ⁝ ✱ ? 
 ❯ git diff                                                                     [21:19:18]
diff --git i/src/main.rs w/src/main.rs
index d658e89..9e9911f 100644
--- i/src/main.rs
+++ w/src/main.rs
@@ -172,8 +172,8 @@ fn main() {

     let cache = Cache::new(config::cache_path("librespot"), true);
     let mut credentials = {
-        let cached_credentials = cache.credentials();
-        match cached_credentials {
+        let cached_credential = cache.credentials();
+        match cached_credential {
             Some(c) => {
                 info!("Using cached credentials");
                 c

ClashTheBunny avatar Jul 20 '21 02:07 ClashTheBunny

Nice, tried it out and it seems to work fine. Probably easier/cleaner than my little script here: https://github.com/afnanenayet/diffsitter/blob/main/assets/git-diffsitter

afnanenayet avatar Jul 20 '21 04:07 afnanenayet

Fixes #155

j-martin avatar Jul 20 '21 05:07 j-martin

When I run git difftool in my repo with a markdown file, it produces Error: Unsupported filetype "md" - is this expected?

gakonst avatar Jul 20 '21 08:07 gakonst

I'm thinking that your script may be useful with a .gitattributes file with supported file types listed like this. That way it only operates on file types that are supported, plus it then works with plain riff. The disadvantage is that you can't get an apply-able diff always...

ClashTheBunny avatar Jul 20 '21 11:07 ClashTheBunny

Ultimately, it would be nice if diffsitter would handle unknown files and show a non-semantic diff. But this is beyond the scope of this. I have opened https://github.com/afnanenayet/diffsitter/issues/160

With an intermediary script I guess it could achieve naively this way: diffsitter "$@" || diff "$@".

j-martin avatar Jul 20 '21 19:07 j-martin

When I run git difftool in my repo with a markdown file, it produces Error: Unsupported filetype "md" - is this expected?

According to the readme in repo, it doesn't support markdown.

diffsitter supports the following languages:

Bash C# C++ CSS Go Java OCaml PHP Python Ruby Rust

There are some comments below mentioning the need to handle unsupported file type more graceful.

pakls avatar Jul 29 '21 12:07 pakls

We gracefully handle unsupported filetypes now that #212 has been merged

afnanenayet avatar Oct 17 '21 01:10 afnanenayet

Does this supersede #208 ?

haolly avatar Dec 03 '22 16:12 haolly

No, I think I wanted to make the git experience more ergonomic so I never ended up merging that PR.

afnanenayet avatar Dec 08 '22 01:12 afnanenayet