From 22f515824408b502e285c80bf2da038aae5af254 Mon Sep 17 00:00:00 2001
From: Cesar Velazquez <cesar.velazquez@disney.com>
Date: Mon, 30 Jan 2023 15:57:54 -0800
Subject: [PATCH 1/4] Enable user to override default diff -M arg

---
 git/diff.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/git/diff.py b/git/diff.py
index c4424592f..79b02f12e 100644
--- a/git/diff.py
+++ b/git/diff.py
@@ -144,7 +144,10 @@ def diff(
         args.append("--abbrev=40")  # we need full shas
         args.append("--full-index")  # get full index paths, not only filenames
 
-        args.append("-M")  # check for renames, in both formats
+        # remove default '-M' arg (check for renames) if user is overriding it
+        if not any(x in kwargs for x in ('find_renames', 'no_renames','M')):
+            args.append("-M")
+
         if create_patch:
             args.append("-p")
         else:

From 6cf3661d6be63b19cd64a18776a2fb575522a9e2 Mon Sep 17 00:00:00 2001
From: Cesar Velazquez <cesar.velazquez@disney.com>
Date: Mon, 30 Jan 2023 17:03:45 -0800
Subject: [PATCH 2/4] fixed lint error

---
 git/diff.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/git/diff.py b/git/diff.py
index 79b02f12e..c1a5bd26f 100644
--- a/git/diff.py
+++ b/git/diff.py
@@ -145,7 +145,7 @@ def diff(
         args.append("--full-index")  # get full index paths, not only filenames
 
         # remove default '-M' arg (check for renames) if user is overriding it
-        if not any(x in kwargs for x in ('find_renames', 'no_renames','M')):
+        if not any(x in kwargs for x in ('find_renames', 'no_renames', 'M')):
             args.append("-M")
 
         if create_patch:

From 186d75c6ba283fd1bb0647ae94a3a8054197c42b Mon Sep 17 00:00:00 2001
From: Cesar Velazquez <cesar.velazquez@disney.com>
Date: Tue, 31 Jan 2023 17:59:58 -0800
Subject: [PATCH 3/4] Added diff test to disable rename detection

---
 test/test_diff.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/test/test_diff.py b/test/test_diff.py
index 7065f0635..16d902097 100644
--- a/test/test_diff.py
+++ b/test/test_diff.py
@@ -411,3 +411,50 @@ def test_diff_interface(self):
         cp = c.parents[0]
         diff_index = c.diff(cp, ["does/not/exist"])
         self.assertEqual(len(diff_index), 0)
+
+    @with_rw_directory
+    def test_rename_override(self, rw_dir):
+        """Test disabling of diff rename detection""" 
+
+        # create and commit file_a.txt
+        repo = Repo.init(rw_dir)
+        file_a = osp.join(rw_dir, "file_a.txt")
+        with open(file_a, "w", encoding='utf-8') as outfile:
+            outfile.write("hello world")
+        repo.git.add(Git.polish_url(file_a))
+        repo.git.commit(message="Added file_a.txt")
+
+        # remove file_a.txt
+        repo.git.rm(Git.polish_url(file_a))
+
+        # create and commit file_b.txt
+        file_b = osp.join(rw_dir, "file_b.txt")
+        with open(file_b, "w", encoding='utf-8') as outfile:
+            outfile.write("hello world")
+        repo.git.add(Git.polish_url(file_b))
+        repo.git.commit(message="Removed file_a.txt. Added file_b.txt")
+
+        commit_a = repo.commit('HEAD')
+        commit_b = repo.commit('HEAD~1')
+
+        # check default diff command with renamed files enabled
+        diffs = commit_b.diff(commit_a)
+        self.assertEqual(1, len(diffs))
+        diff = diffs[0]
+        self.assertEqual(True, diff.renamed_file)
+        self.assertEqual('file_a.txt', diff.rename_from)
+        self.assertEqual('file_b.txt', diff.rename_to)
+
+        # check diff with rename files disabled
+        diffs = commit_b.diff(commit_a, no_renames=True)
+        self.assertEqual(2, len(diffs))
+
+        # check fileA.txt deleted
+        diff = diffs[0]
+        self.assertEqual(True, diff.deleted_file)
+        self.assertEqual('file_a.txt', diff.a_path)
+
+        # check fileB.txt added
+        diff = diffs[1]
+        self.assertEqual(True, diff.new_file)
+        self.assertEqual('file_b.txt', diff.a_path)

From c0e69a4263a7f42b7a7d8bb44d11ee3d14a27545 Mon Sep 17 00:00:00 2001
From: Cesar Velazquez <cesar.velazquez@disney.com>
Date: Wed, 1 Feb 2023 23:02:56 -0800
Subject: [PATCH 4/4] Updated diff test to use different similarity thresholds

---
 test/test_diff.py | 29 ++++++++++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)

diff --git a/test/test_diff.py b/test/test_diff.py
index 16d902097..504337744 100644
--- a/test/test_diff.py
+++ b/test/test_diff.py
@@ -420,17 +420,17 @@ def test_rename_override(self, rw_dir):
         repo = Repo.init(rw_dir)
         file_a = osp.join(rw_dir, "file_a.txt")
         with open(file_a, "w", encoding='utf-8') as outfile:
-            outfile.write("hello world")
+            outfile.write("hello world\n")
         repo.git.add(Git.polish_url(file_a))
         repo.git.commit(message="Added file_a.txt")
 
         # remove file_a.txt
         repo.git.rm(Git.polish_url(file_a))
 
-        # create and commit file_b.txt
+        # create and commit file_b.txt with similarity index of 52
         file_b = osp.join(rw_dir, "file_b.txt")
         with open(file_b, "w", encoding='utf-8') as outfile:
-            outfile.write("hello world")
+            outfile.write("hello world\nhello world")
         repo.git.add(Git.polish_url(file_b))
         repo.git.commit(message="Removed file_a.txt. Added file_b.txt")
 
@@ -458,3 +458,26 @@ def test_rename_override(self, rw_dir):
         diff = diffs[1]
         self.assertEqual(True, diff.new_file)
         self.assertEqual('file_b.txt', diff.a_path)
+
+        # check diff with high similarity index
+        diffs = commit_b.diff(commit_a, split_single_char_options=False, M='75%')
+        self.assertEqual(2, len(diffs))
+
+        # check fileA.txt deleted
+        diff = diffs[0]
+        self.assertEqual(True, diff.deleted_file)
+        self.assertEqual('file_a.txt', diff.a_path)
+
+        # check fileB.txt added
+        diff = diffs[1]
+        self.assertEqual(True, diff.new_file)
+        self.assertEqual('file_b.txt', diff.a_path)
+
+        # check diff with low similarity index
+        diffs = commit_b.diff(commit_a, split_single_char_options=False, M='40%')
+        self.assertEqual(1, len(diffs))
+        diff = diffs[0]
+        self.assertEqual(True, diff.renamed_file)
+        self.assertEqual('file_a.txt', diff.rename_from)
+        self.assertEqual('file_b.txt', diff.rename_to)
+