Add additional logging for importing course from git
This commit is contained in:
@@ -97,23 +97,28 @@ def add_repo(repo, rdir_in):
|
||||
cwd = os.path.abspath(cwd)
|
||||
try:
|
||||
ret_git = cmd_log(cmd, cwd=cwd)
|
||||
except subprocess.CalledProcessError:
|
||||
except subprocess.CalledProcessError as ex:
|
||||
log.exception('Error running git pull: %r', ex.output)
|
||||
raise GitImportError(GitImportError.CANNOT_PULL)
|
||||
|
||||
# get commit id
|
||||
cmd = ['git', 'log', '-1', '--format=%H', ]
|
||||
try:
|
||||
commit_id = cmd_log(cmd, cwd=rdirp)
|
||||
except subprocess.CalledProcessError:
|
||||
except subprocess.CalledProcessError as ex:
|
||||
log.exception('Unable to get git log: %r', ex.output)
|
||||
raise GitImportError(GitImportError.BAD_REPO)
|
||||
|
||||
ret_git += '\nCommit ID: {0}'.format(commit_id)
|
||||
|
||||
# get branch
|
||||
cmd = ['git', 'rev-parse', '--abbrev-ref', 'HEAD', ]
|
||||
cmd = ['git', 'symbolic-ref', '--short', 'HEAD', ]
|
||||
try:
|
||||
branch = cmd_log(cmd, cwd=rdirp)
|
||||
except subprocess.CalledProcessError:
|
||||
except subprocess.CalledProcessError as ex:
|
||||
# I can't discover a way to excercise this, but git is complex
|
||||
# so still logging and raising here in case.
|
||||
log.exception('Unable to determine branch: %r', ex.output)
|
||||
raise GitImportError(GitImportError.BAD_REPO)
|
||||
|
||||
ret_git += '{0}Branch: {1}'.format(' \n', branch)
|
||||
|
||||
@@ -102,3 +102,21 @@ class TestGitAddCourse(ModuleStoreTestCase):
|
||||
|
||||
with self.assertRaisesRegexp(GitImportError, GitImportError.BAD_REPO):
|
||||
git_import.add_repo('file://{0}'.format(bare_repo), None)
|
||||
|
||||
def test_detached_repo(self):
|
||||
"""
|
||||
Test repo that is in detached head state.
|
||||
"""
|
||||
repo_dir = getattr(settings, 'GIT_REPO_DIR')
|
||||
# Test successful import from command
|
||||
try:
|
||||
os.mkdir(repo_dir)
|
||||
except OSError:
|
||||
pass
|
||||
self.addCleanup(shutil.rmtree, repo_dir)
|
||||
git_import.add_repo(self.TEST_REPO, repo_dir / 'edx4edx_lite')
|
||||
subprocess.check_output(['git', 'checkout', 'HEAD~2', ],
|
||||
stderr=subprocess.STDOUT,
|
||||
cwd=repo_dir / 'edx4edx_lite')
|
||||
with self.assertRaisesRegexp(GitImportError, GitImportError.CANNOT_PULL):
|
||||
git_import.add_repo(self.TEST_REPO, repo_dir / 'edx4edx_lite')
|
||||
|
||||
Reference in New Issue
Block a user