Skip to content

Commit

Permalink
Reseting the file cache when changing the target branch
Browse files Browse the repository at this point in the history
* Fixing cache files bug

* Bumped the version and updated changelog
  • Loading branch information
AgarFu authored Jun 18, 2020
1 parent d678e05 commit e5f1f88
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com),
and this project adheres to [Semantic Versioning](https://semver.org).

## [1.4.1] - 2020-06-18
### Fixed
- set_target_branch was not cleaning the file cache, resulting in gordian not being able to get new files in the new branches.

## [1.4.0] - 2020-06-17
### Added
- Print out PR URLs at the end of a Gordian run
Expand Down
6 changes: 6 additions & 0 deletions gordian/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def __init__(self, repo_name, github_api_url=None, branch=None, git=None, files=
self.dirty = False
self.new_version = None
self.semver_label = semver_label
self.target_branch = None
self.set_target_branch(target_branch)

logger.debug(f'Target ref: {target_branch}')
Expand All @@ -50,8 +51,13 @@ def __init__(self, repo_name, github_api_url=None, branch=None, git=None, files=
logger.debug(f'Branch name for this changes: {self.branch_name}')

def set_target_branch(self, branch):
if branch == self.target_branch:
return

self.target_branch = branch
self.target_ref = f"refs/heads/{self.target_branch}"
# Resetting the file cache when we change the branch
self.files = []

def get_objects(self, filename, klass=None):
file = self.find_file(filename)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
setup_reqs = ['pytest', 'pytest-cov', 'pytest-runner', 'flake8']
setuptools.setup(
name="gordian",
version="1.4.0",
version="1.4.1",
author="Intuit",
author_email="[email protected]",
description="A tool to search and replace files in a Git repo",
Expand Down
11 changes: 11 additions & 0 deletions tests/test_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,14 @@ def test_get_files(self):
self.repo.get_files()
self.repo._repo.get_contents.assert_has_calls([call('', 'refs/heads/target'), call('directory', 'refs/heads/target')])
self.assertEquals(self.repo.files, [repository_file])

def test_set_target_branch(self):
cached_files = ['cached_file', 'cached_file', 'cached_file']
self.repo.files = cached_files.copy()
self.repo.set_target_branch('master')
self.assertEqual(self.repo.files, cached_files)

self.repo.set_target_branch('Something different')
self.assertEqual(self.repo.files, [])
self.assertEqual(self.repo.target_branch, 'Something different')
self.assertEqual(self.repo.target_ref, 'refs/heads/Something different')

0 comments on commit e5f1f88

Please sign in to comment.