Skip to content

Commit

Permalink
Merge pull request ESCOMP#156 from billsacks/onbranch_show_hash
Browse files Browse the repository at this point in the history
When on a branch, show tag/hash, too

For the sake of recording provenance, it is not sufficient to know the branch you're on: you also need to know the hash or tag. So show both when printing the current reference.

Example output of excerpts from `checkout_externals -S -v`:

In sync:

```
    ./cime/src/drivers/nuopc/
        clean sandbox, on 3810a7a000e993267e1774c9a985891db3f9d137 (branch mvertens/fixglc_runseq)
```

Out of sync:

```
s   ./cime/src/drivers/nuopc/
        clean sandbox, 3810a7a000e993267e1774c9a985891db3f9d137 (branch mvertens/fixglc_runseq) --> 147e8a6
```

Previously in these cases, the current hash (`3810a7a...`) wasn't shown: only the branch name was shown.

User interface changes?: Yes: Just changes output a bit

Fixes: none

Testing:
  test removed: none
  unit tests: pass
  system tests: pass
  manual testing: manually checked output in a few cases (e.g., see above)
  • Loading branch information
billsacks authored Nov 25, 2020
2 parents 39ad532 + 952e44d commit e954582
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
3 changes: 3 additions & 0 deletions manic/externals_description.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ def parse_submodules_desc_section(section_items, file_path):
def read_gitmodules_file(root_dir, file_name):
# pylint: disable=deprecated-method
# Disabling this check because the method is only used for python2
# pylint: disable=too-many-locals
# pylint: disable=too-many-branches
# pylint: disable=too-many-statements
"""Read a .gitmodules file and convert it to be compatible with an
externals description.
"""
Expand Down
29 changes: 14 additions & 15 deletions manic/repository_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,35 +109,34 @@ def _clone_repo(self, base_dir_path, repo_dir_name, verbosity):
def _current_ref(self):
"""Determine the *name* associated with HEAD.
If we're on a branch, then returns the branch name; otherwise,
if we're on a tag, then returns the tag name; otherwise, returns
If we're on a tag, then returns the tag name; otherwise, returns
the current hash. Returns an empty string if no reference can be
determined (e.g., if we're not actually in a git repository).
If we're on a branch, then the branch name is also included in
the returned string (in addition to the tag / hash).
"""
ref_found = False

# If we're on a branch, then use that as the current ref
branch_found, branch_name = self._git_current_branch()
if branch_found:
current_ref = branch_name
# If we're exactly at a tag, use that as the current ref
tag_found, tag_name = self._git_current_tag()
if tag_found:
current_ref = tag_name
ref_found = True

if not ref_found:
# Otherwise, if we're exactly at a tag, use that as the
# current ref
tag_found, tag_name = self._git_current_tag()
if tag_found:
current_ref = tag_name
ref_found = True

if not ref_found:
# Otherwise, use current hash as the current ref
hash_found, hash_name = self._git_current_hash()
if hash_found:
current_ref = hash_name
ref_found = True

if not ref_found:
if ref_found:
# If we're on a branch, include branch name in current ref
branch_found, branch_name = self._git_current_branch()
if branch_found:
current_ref = "{} (branch {})".format(current_ref, branch_name)
else:
# If we still can't find a ref, return empty string. This
# can happen if we're not actually in a git repo
current_ref = ''
Expand Down
1 change: 0 additions & 1 deletion test/test_sys_checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import os
import os.path
import shutil
import sys
import unittest

from manic.externals_description import ExternalsDescription
Expand Down
2 changes: 1 addition & 1 deletion test/test_unit_repository_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def test_ref_branch(self):
True, 'feature3')
self._repo._git_current_tag = self._git_current_tag(True, 'foo_tag')
self._repo._git_current_hash = self._git_current_hash(True, 'abc123')
expected = 'feature3'
expected = 'foo_tag (branch feature3)'
result = self._repo._current_ref()
self.assertEqual(result, expected)

Expand Down

0 comments on commit e954582

Please sign in to comment.