Repository: albertyw/git-reviewers

Issue:
Make git-reviewers work with commits that only add new files
Read reviewers from entire repository history

Discussion:

Patch:
diff --git a/git_reviewers/reviewers.py b/git_reviewers/reviewers.py
index e4eee15..77ec78e 100755
--- a/git_reviewers/reviewers.py
+++ b/git_reviewers/reviewers.py
@@ -101,6 +101,18 @@ class FindLogReviewers(FindFileLogReviewers):
         """ Find the changed files between current status and master """
         git_diff_files_command = ['git', 'diff', 'master', '--name-only']
         git_diff_files = self.run_command(git_diff_files_command)
+        if not git_diff_files:
+            return FindHistoricalReviewers().get_changed_files()
+        return git_diff_files
+
+
+class FindHistoricalReviewers(FindFileLogReviewers):
+    def get_changed_files(self) -> List[str]:
+        """Find all git files """
+        git_diff_files_command = [
+            'git', 'ls-tree', '-r', 'master', '--name-only'
+        ]
+        git_diff_files = self.run_command(git_diff_files_command)
         return git_diff_files
 
 


Test patch:
diff --git a/git_reviewers/tests/test.py b/git_reviewers/tests/test.py
index 87e2df4..933ebd6 100644
--- a/git_reviewers/tests/test.py
+++ b/git_reviewers/tests/test.py
@@ -110,6 +110,27 @@ class TestLogReviewers(unittest.TestCase):
         files = self.finder.get_changed_files()
         self.assertEqual(files, ['README.rst', 'setup.py'])
 
+    @patch('git_reviewers.reviewers.FindHistoricalReviewers')
+    @patch('subprocess.run')
+    def test_no_diffs(self, mock_run, mock_historical):
+        process = MagicMock()
+        process.stdout = b''
+        mock_run.return_value = process
+        mock_historical().get_changed_files.return_value = ['asdf']
+        files = self.finder.get_changed_files()
+        self.assertEqual(files, ['asdf'])
+
+
+class TestHistoricalReviewers(unittest.TestCase):
+    def setUp(self):
+        self.finder = reviewers.FindHistoricalReviewers()
+
+    def test_get_changed_files(self):
+        changed_files = ['README.rst', 'setup.py']
+        self.finder.run_command = MagicMock(return_value=changed_files)
+        files = self.finder.get_changed_files()
+        self.assertEqual(files, ['README.rst', 'setup.py'])
+
 
 class TestFindArcCommitReviewers(unittest.TestCase):
     def setUp(self):