diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index bdd18634..96423fb7 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -22,12 +22,6 @@ jobs: with: ref: ${{ github.event.pull_request.head.sha }} # Checkout pull request HEAD commit instead of merge commit - # Because gitlint is a tool that uses git itself under the hood, we remove git tracking from the checked out - # code by temporarily renaming the .git directory. - # This is to ensure that the tests don't have a dependency on the version control of gitlint itself. - - name: Temporarily remove git version control from code - run: mv .git ._git - - name: Setup python uses: actions/setup-python@v4.2.0 with: @@ -85,10 +79,6 @@ jobs: # with: # github-token: ${{ secrets.GITHUB_TOKEN }} - # Re-add git version control so we can run gitlint on itself. - - name: Re-add git version control to code - run: mv ._git .git - # Run gitlint. Skip during PR runs, since PR commit messages are transient and usually full of gitlint violations. # PRs get squashed and get a proper commit message during merge. - name: Gitlint check diff --git a/gitlint-core/gitlint/tests/base.py b/gitlint-core/gitlint/tests/base.py index 710efe2b..7f4afcf2 100644 --- a/gitlint-core/gitlint/tests/base.py +++ b/gitlint-core/gitlint/tests/base.py @@ -30,10 +30,28 @@ class BaseTestCase(unittest.TestCase): # In case of assert failures, print the full error message maxDiff = None + # Working directory in which tests in this class are executed + working_dir = None + # Originally working dir when the test was started + original_working_dir = None + SAMPLES_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "samples") EXPECTED_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "expected") GITLINT_USE_SH_LIB = os.environ.get("GITLINT_USE_SH_LIB", "[NOT SET]") + @classmethod + def setUpClass(cls): + # Run tests a temporary directory to shield them from any local git config + cls.original_working_dir = os.getcwd() + cls.working_dir = tempfile.mkdtemp() + os.chdir(cls.working_dir) + + @classmethod + def tearDownClass(cls): + # Go back to original working dir and remove our temp working dir + os.chdir(cls.original_working_dir) + shutil.rmtree(cls.working_dir) + def setUp(self): self.logcapture = LogCapture() self.logcapture.setFormatter(logging.Formatter(LOG_FORMAT)) diff --git a/gitlint-core/gitlint/tests/test_options.py b/gitlint-core/gitlint/tests/test_options.py index 7b146e72..486de43a 100644 --- a/gitlint-core/gitlint/tests/test_options.py +++ b/gitlint-core/gitlint/tests/test_options.py @@ -158,7 +158,7 @@ def test_path_option(self): option = PathOption("tëst-directory", ".", "Tëst Description", type="dir") self.assertEqual(option.name, "tëst-directory") self.assertEqual(option.description, "Tëst Description") - self.assertEqual(option.value, os.getcwd()) + self.assertEqual(option.value, os.path.realpath(".")) self.assertEqual(option.type, "dir") # re-set value