Skip to content

Commit

Permalink
Added git clean to git export feature
Browse files Browse the repository at this point in the history
This ensures that additional exports of the content are the
same the first.
  • Loading branch information
carsongee committed Sep 5, 2014
1 parent 9abd353 commit 0891d9a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions cms/djangoapps/contentstore/git_export_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def export_to_git(course_id, repo, user='', rdir=None):
['git', 'fetch', 'origin'],
['git', 'reset', '--hard', 'origin/{0}'.format(branch)],
['git', 'pull'],
['git', 'clean', '-d', '-f'],
]
else:
cmds = [['git', 'clone', repo]]
Expand Down
27 changes: 27 additions & 0 deletions cms/djangoapps/contentstore/tests/test_export_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,30 @@ def test_repo_with_dots(self):
self.make_bare_repo_with_course('test.repo')
response = self.client.get('{}?action=push'.format(self.test_url))
self.assertIn('Export Succeeded', response.content)

def test_dirty_repo(self):
"""
Add additional items not in the repo and make sure they aren't
there after the export. This allows old content to removed
in the repo.
"""
repo_name = 'dirty_repo1'
self.make_bare_repo_with_course(repo_name)
git_export_utils.export_to_git(self.course.id,
self.course_module.giturl, self.user)

# Make arbitrary change to course to make diff
self.course_module.matlab_api_key = 'something'
modulestore().update_item(self.course_module, self.user.id)
# Touch a file in the directory, export again, and make sure
# the test file is gone
repo_dir = os.path.join(
os.path.abspath(git_export_utils.GIT_REPO_EXPORT_DIR),
repo_name
)
test_file = os.path.join(repo_dir, 'test.txt')
open(test_file, 'a').close()
self.assertTrue(os.path.isfile(test_file))
git_export_utils.export_to_git(self.course.id,
self.course_module.giturl, self.user)
self.assertFalse(os.path.isfile(test_file))

0 comments on commit 0891d9a

Please sign in to comment.