Skip to content

Commit 7f5698f

Browse files
committed
Handle cases of detached heads when deducing scm branch
1 parent 66530b7 commit 7f5698f

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

backslash/contrib/slash_plugin.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,11 @@ def _update_scm_info(self, test_info):
342342
test_info['scm_revision'] = hexsha
343343
test_info['scm_dirty'] = bool(repo.untracked_files or repo.index.diff(None) or repo.index.diff(repo.head.commit))
344344
if self.client.api.info().endpoints.report_test_start.version >= 3:
345-
test_info['scm_local_branch'] = repo.active_branch.name
346-
tracking_branch = repo.active_branch.tracking_branch()
347-
if tracking_branch is not None:
348-
test_info['scm_remote_branch'] = tracking_branch.name
345+
if not repo.head.is_detached:
346+
test_info['scm_local_branch'] = repo.active_branch.name
347+
tracking_branch = repo.active_branch.tracking_branch()
348+
if tracking_branch is not None:
349+
test_info['scm_remote_branch'] = tracking_branch.name
349350
except Exception: # pylint: disable=broad-except
350351
_logger.warning('Error when obtaining SCM information', exc_info=True)
351352

docs/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Changelog
22
=========
33

4+
* :bug:`54` Handle cases of detached head correctly when deducing local branch
45
* :release:`2.31.1 <11-9-2017>`
56
* :bug:`53` Use api session when constructing lazy queries
67
* :release:`2.31.0 <10-9-2017>`

0 commit comments

Comments
 (0)