workdir: fix lockingv0.3
authorSteven Walter <swalter@lpdev.prtdev.lexmark.com>
Thu, 5 Feb 2009 14:51:17 +0000 (5 09:51 -0500)
committerSteven Walter <swalter@lpdev.prtdev.lexmark.com>
Thu, 5 Feb 2009 14:51:17 +0000 (5 09:51 -0500)
In some cases the lockfile contained a relative path, which caused the
existance test te behave oddly

plugins/workdir.py

index 96a2c92..9b4b3d6 100644 (file)
@@ -57,6 +57,13 @@ class WorkdirPlugin(YapCore):
        finally:
            os.unlink(tmplock)
 
+    def _get_repodir(self):
+        repo = get_output('git rev-parse --git-dir')[0]
+       if not repo.startswith('/'):
+           repo = os.path.join(os.getcwd(), repo)
+        repodir = os.path.dirname(repo)
+       return repodir
+
     def cmd_workdir(self, branch, workdir=None):
         "<branch> [workdir]"
 
@@ -67,10 +74,8 @@ class WorkdirPlugin(YapCore):
             raise YapError("Not a branch: %s" % branch)
 
         current = get_output("git symbolic-ref HEAD")[0]
-
-        repo = get_output('git rev-parse --git-dir')[0]
-        repo = os.path.join(os.getcwd(), repo)
-        repodir = os.path.dirname(repo)
+       repodir = self._get_repodir()
+       repo = os.path.join(repodir, '.git')
         if workdir is None:
             repoparent, reponame = os.path.split(repodir)
             workdir = os.path.join(repoparent, "%s-%s" % (reponame, branch))
@@ -110,8 +115,8 @@ class WorkdirPlugin(YapCore):
 
         current = get_output("git symbolic-ref HEAD")[0]
 
-        repo = get_output('git rev-parse --git-dir')[0]
-        self._lock_branch(branch, repo)
+       repodir = self._get_repodir()
+        self._lock_branch(branch, repodir)
 
         try:
             super(WorkdirPlugin, self).cmd_switch(branch, *args, **flags)