[PATCH 3/5] git.py: Add get_project_description()



---
 git.py |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/git.py b/git.py
index 2117f82..72adff1 100644
--- a/git.py
+++ b/git.py
@@ -191,4 +191,21 @@ def get_module_name():
 
     return projectshort
 
+# Return the project description or '' if it is 'Unnamed repository;'
+def get_project_description():
+    try:
+        git_dir = git.rev_parse(git_dir=True, _quiet=True)
+    except CalledProcessError:
+        die("GIT_DIR not set")
 
+    projectdesc = ''
+    description = os.path.join(git_dir, 'description')
+    if os.path.exists(description):
+        try:
+            projectdesc = open(description).read().strip()
+        except:
+            pass
+    if projectdesc.startswith('Unnamed repository;'):
+        projectdesc = ''
+
+    return projectdesc
-- 
1.6.3.3



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]