Repository: JrGoodle/clowder

Issue:
Support short commit hashes
Use for output display

Comments:

Patch:
diff --git a/clowder/cmd.py b/clowder/cmd.py
index cf55992f..940b8ff6 100644
--- a/clowder/cmd.py
+++ b/clowder/cmd.py
@@ -646,7 +646,7 @@ def exit_unrecognized_command(parser):
 
 def exit_clowder_not_found():
     """Print clowder not found message and exit"""
-    cprint('No clowder found in the current directory\n', 'red')
+    cprint(' - No clowder found in the current directory\n', 'red')
     sys.exit(1)
 
 def main():
diff --git a/clowder/project.py b/clowder/project.py
index f46f2a1a..dc7a598b 100644
--- a/clowder/project.py
+++ b/clowder/project.py
@@ -17,7 +17,6 @@ from clowder.utility.git_print_utilities import (
 )
 from clowder.utility.git_utilities import (
     git_create_repo,
-    git_current_sha,
     git_existing_local_branch,
     git_existing_remote_branch,
     git_existing_repository,
@@ -28,6 +27,7 @@ from clowder.utility.git_utilities import (
     git_prune_local,
     git_prune_remote,
     git_reset_head,
+    git_sha_long,
     git_start,
     git_stash,
     git_status,
@@ -125,7 +125,7 @@ class Project(object):
                 'path': self.path,
                 'depth': self.depth,
                 'forks': forks_yaml,
-                'ref': git_current_sha(self.full_path()),
+                'ref': git_sha_long(self.full_path()),
                 'remote': self.remote_name,
                 'source': self.source.name}
 
diff --git a/clowder/utility/git_print_utilities.py b/clowder/utility/git_print_utilities.py
index e048ee99..cde9d04a 100644
--- a/clowder/utility/git_print_utilities.py
+++ b/clowder/utility/git_print_utilities.py
@@ -2,12 +2,12 @@
 from termcolor import colored, cprint
 from clowder.utility.git_utilities import (
     git_current_branch,
-    git_current_sha,
     git_existing_repository,
     git_is_detached,
     git_is_dirty,
     git_new_local_commits,
-    git_new_upstream_commits
+    git_new_upstream_commits,
+    git_sha_short
 )
 
 def format_project_string(repo_path, name):
@@ -34,7 +34,7 @@ def format_project_ref_string(repo_path):
         status = ' (' + local_commits_output + '/' + upstream_commits_output + ')'
 
     if git_is_detached(repo_path):
-        current_ref = git_current_sha(repo_path)
+        current_ref = git_sha_short(repo_path)
         return colored('(HEAD @ ' + current_ref + ')', 'magenta')
     else:
         current_branch = git_current_branch(repo_path)
diff --git a/clowder/utility/git_utilities.py b/clowder/utility/git_utilities.py
index 722906c9..a6091d76 100644
--- a/clowder/utility/git_utilities.py
+++ b/clowder/utility/git_utilities.py
@@ -71,7 +71,7 @@ def git_create_repo(url, repo_path, remote, ref, depth=0):
             try:
                 shutil.rmtree(repo_path)
             except:
-                message = colored(" - Failed remove directory ", 'red')
+                message = colored(" - Failed to remove directory ", 'red')
                 print(message + format_path(repo_path))
             finally:
                 print()
@@ -93,7 +93,7 @@ def git_create_repo(url, repo_path, remote, ref, depth=0):
                     try:
                         shutil.rmtree(repo_path)
                     except:
-                        message = colored(" - Failed remove directory ", 'red')
+                        message = colored(" - Failed to remove directory ", 'red')
                         print(message + format_path(repo_path))
                     finally:
                         print()
@@ -121,11 +121,6 @@ def git_current_branch(repo_path):
     repo = _repo(repo_path)
     return repo.head.ref.name
 
-def git_current_sha(repo_path):
-    """Return current git sha for checked out commit"""
-    repo = _repo(repo_path)
-    return repo.head.commit.hexsha
-
 def git_existing_repository(path):
     """Check if a git repository exists"""
     return os.path.isdir(os.path.join(path, '.git'))
@@ -345,6 +340,17 @@ def git_reset_head(repo_path):
     repo = _repo(repo_path)
     repo.head.reset(index=True, working_tree=True)
 
+def git_sha_long(repo_path):
+    """Return long sha for currently checked out commit"""
+    repo = _repo(repo_path)
+    return repo.head.commit.hexsha
+
+def git_sha_short(repo_path):
+    """Return short sha of currently checked out commit"""
+    repo = _repo(repo_path)
+    sha = repo.head.commit.hexsha
+    return repo.git.rev_parse(sha, short=True)
+
 def git_start(repo_path, remote, branch, depth, tracking):
     """Start new branch in repository"""
     repo = _repo(repo_path)


Test patch:
diff --git a/test/test_git_utilities.py b/test/test_git_utilities.py
index 8b887c39..4bab4333 100644
--- a/test/test_git_utilities.py
+++ b/test/test_git_utilities.py
@@ -3,9 +3,9 @@ import os
 import unittest
 from clowder.utility.git_utilities import (
     git_current_branch,
-    git_current_sha,
     git_is_detached,
     git_is_dirty,
+    git_sha_long,
     _ref_type,
     _truncate_ref
 )
@@ -26,9 +26,9 @@ class GitUtilitiesTest(unittest.TestCase):
         """Test git_current_branch() function"""
         self.assertEqual(git_current_branch(self.kit_project_path), 'master')
 
-    def test_git_current_sha(self):
-        """Test git_current_sha() function"""
-        self.assertEqual(git_current_sha(self.sasha_project_path), self.sha_ref)
+    def test_git_sha_long(self):
+        """Test git_sha_long() function"""
+        self.assertEqual(git_sha_long(self.sasha_project_path), self.sha_ref)
 
     def test_git_is_detached(self):
         """Test git_is_detached() function"""