import os
import sys
from subprocess import check_output, CalledProcessError

def trigger(*args, **kwargs):
    repo_dir = os.getcwd()  # current directory is where repository resides
    hook_path = args[0]  # relative path to hook:  
                        # e.g. '.git/hooks/post-checkout'
    git_hooks_dir, event = os.path.split(hook_path)  # e.g. '.git/hooks',
                                                          # 'post-checkout'
    git_dir_relative, _ = os.path.split(git_hooks_dir)  # e.g. '.git'
    git_dir = os.path.join(repo_dir, git_dir_relative)
    path_to_gitta_pyfiles = os.path.join(repo_dir)  # EVENTUALLY I want to run
            # only code within .git so EVENTUALLY all gitTA files will be in 
            # .git/gitTA (including hooks and py folders) 
    kwargs.update({'git_dir': git_dir, 'repo_dir': repo_dir, 'event': event})
    # now collect important git info that developer may use in kwargs
    try:
        cmd = ['git', 'symbolic-ref', '--short', 'HEAD']
        branch_current = check_output(cmd).strip()
    except CalledProcessError:  # will print "fatal: ref..." but won't abort
        branch_current = "(detached)"  # for when the HEAD is detached
    head_current = check_output(['git', 'rev-parse', 'HEAD']).strip()
    sys.path.append(path_to_gitta_pyfiles)    # add path so that importing main
                                              # and gitta works
    import main
    import gitTA as git # order is important. MUST import main before GitTA
    git.trigger(*args[1:], **kwargs)

@@ -926,16 +926,17 @@
  kwargs%0A
+#
     try:
@@ -936,16 +936,17 @@
    try:%0A
+#
         
@@ -994,16 +994,17 @@
 'HEAD'%5D%0A
+#
         
@@ -1042,24 +1042,25 @@
 md).strip()%0A
+#
     except C
@@ -1124,16 +1124,17 @@
 t abort%0A
+#
         
@@ -1154,44 +1154,165 @@
 t = 
-%22(detached)%22  # for when the
+None  # for when the HEAD is detached%0A    cmd = %5B'git', 'rev-parse', '--abbrev-ref', 'HEAD'%5D%0A    branch_current = check_output(cmd).strip()  # return
  HEAD i
-s
+f
  det
@@ -1325,73 +1325,276 @@
     
-head_current = check_output(%5B'git', 'rev-parse', 'HEAD'%5D).strip()
+if branch_current == 'HEAD':%0A        branch_current = None  # indicate that we are not on a branch%0A    head_current = check_output(%5B'git', 'rev-parse', 'HEAD'%5D).strip()  # get sha1%0A    kwargs%5B'branch_current'%5D = branch_current%0A    kwargs%5B'head_current'%5D = head_current
 %0A   

use more reliable method for getting branch_current