{"thread":{"id":"13080","subject":"[StGit PATCH 1/2] Don't both change directory and set GIT_WORK_TREE","startedAt":"2008-04-12T15:47:15Z","lastAt":"2008-04-12T15:47:27Z","messageCount":3,"participants":["Karl Hasselström"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"74216","messageId":"20080412154427.19690.71877.stgit@yoghurt","threadId":"13080","inReplyTo":null,"subject":"[StGit PATCH 0/2] Fix stg breakage with nweer gits","fromName":"Karl Hasselström","fromEmail":"kha@treskal.com","sentAt":"2008-04-12T15:47:15Z","receivedAt":"2008-04-12T15:47:15Z","isPatch":true,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"The new-infrastructure commands stopped working with newer gits, due\nto git merge-recursive starting to heed GIT_WORK_TREE. Patch 1/2 fixes\nthis issue; patch 2/2 is some debugging stuff I built while tracking\ndown the bug.\n\nErik, this fixes your bug.\n\n---\n\nKarl Hasselström (2):\n      Log environment and cwd as well as the actual command\n      Don't both change directory and set GIT_WORK_TREE\n\n\n stgit/lib/git.py |   14 +++++++++-----\n stgit/run.py     |    6 ++++++\n 2 files changed, 15 insertions(+), 5 deletions(-)\n\n-- \nKarl Hasselström, kha@treskal.com\n      www.treskal.com/kalle\n"},{"id":"74215","messageId":"20080412154722.19690.87411.stgit@yoghurt","threadId":"13080","inReplyTo":"20080412154427.19690.71877.stgit@yoghurt","subject":"[StGit PATCH 1/2] Don't both change directory and set GIT_WORK_TREE","fromName":"Karl Hasselström","fromEmail":"kha@treskal.com","sentAt":"2008-04-12T15:47:22Z","receivedAt":"2008-04-12T15:47:22Z","isPatch":true,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"We used to both change the working directory and set GIT_WORK_TREE\nwhen calling git merge-recursive. This works with older versions of\ngit (up to and including 1.5.4.x, or thereabouts) because\nmerge-recursive ignores GIT_WORK_TREE. It stopped doing that sometime\njust before 1.5.5, which broke StGit. (Given both GIT_WORK_TREE=\"..\"\nand cwd \"..\", it assumed the work tree was at \"../..\", instead of just\n\"..\" like we intended. This made t2800 fail.)\n\nJust dropping the cd would solve the problem for new gits, but would\nbreak StGit with older gits. But it works in both cases if we keep the\ncd, and unconditionally set GIT_WORK_TREE=\".\". So this patch does\nprecisely that.\n\n(git read-tree -u -m is also called from IndexAndWorktree, and it\n seems to always ignore GIT_WORK_TREE just like merge-recursive used\n to do. The patch fixes all calls made from IndexAndWorktree, so we're\n good if read-tree starts heeding GIT_WORK_TREE in the future.)\n\nSigned-off-by: Karl Hasselström <kha@treskal.com>\n\n---\n\n stgit/lib/git.py |   14 +++++++++-----\n 1 files changed, 9 insertions(+), 5 deletions(-)\n\n\ndiff --git a/stgit/lib/git.py b/stgit/lib/git.py\nindex 35b9bbf..c5b048f 100644\n--- a/stgit/lib/git.py\n+++ b/stgit/lib/git.py\n@@ -298,6 +298,10 @@ class RunWithEnv(object):\n     def run(self, args, env = {}):\n         return run.Run(*args).env(utils.add_dict(self.env, env))\n \n+class RunWithEnvCwd(RunWithEnv):\n+    def run(self, args, env = {}):\n+        return RunWithEnv.run(self, args, env).cwd(self.cwd)\n+\n class Repository(RunWithEnv):\n     def __init__(self, directory):\n         self.__git_dir = directory\n@@ -490,19 +494,20 @@ class Index(RunWithEnv):\n class Worktree(object):\n     def __init__(self, directory):\n         self.__directory = directory\n-    env = property(lambda self: { 'GIT_WORK_TREE': self.__directory })\n+    env = property(lambda self: { 'GIT_WORK_TREE': '.' })\n     directory = property(lambda self: self.__directory)\n \n class CheckoutException(exception.StgException):\n     pass\n \n-class IndexAndWorktree(RunWithEnv):\n+class IndexAndWorktree(RunWithEnvCwd):\n     def __init__(self, index, worktree):\n         self.__index = index\n         self.__worktree = worktree\n     index = property(lambda self: self.__index)\n     env = property(lambda self: utils.add_dict(self.__index.env,\n                                                self.__worktree.env))\n+    cwd = property(lambda self: self.__worktree.directory)\n     def checkout(self, old_tree, new_tree):\n         # TODO: Optionally do a 3-way instead of doing nothing when we\n         # have a problem. Or maybe we should stash changes in a patch?\n@@ -512,7 +517,7 @@ class IndexAndWorktree(RunWithEnv):\n             self.run(['git', 'read-tree', '-u', '-m',\n                       '--exclude-per-directory=.gitignore',\n                       old_tree.sha1, new_tree.sha1]\n-                     ).cwd(self.__worktree.directory).discard_output()\n+                     ).discard_output()\n         except run.RunException:\n             raise CheckoutException('Index/workdir dirty')\n     def merge(self, base, ours, theirs):\n@@ -524,8 +529,7 @@ class IndexAndWorktree(RunWithEnv):\n                           theirs.sha1],\n                          env = { 'GITHEAD_%s' % base.sha1: 'ancestor',\n                                  'GITHEAD_%s' % ours.sha1: 'current',\n-                                 'GITHEAD_%s' % theirs.sha1: 'patched'}\n-                         ).cwd(self.__worktree.directory)\n+                                 'GITHEAD_%s' % theirs.sha1: 'patched'})\n             r.discard_output()\n         except run.RunException, e:\n             if r.exitcode == 1:\n"},{"id":"74217","messageId":"20080412154727.19690.60228.stgit@yoghurt","threadId":"13080","inReplyTo":"20080412154427.19690.71877.stgit@yoghurt","subject":"[StGit PATCH 2/2] Log environment and cwd as well as the actual command","fromName":"Karl Hasselström","fromEmail":"kha@treskal.com","sentAt":"2008-04-12T15:47:27Z","receivedAt":"2008-04-12T15:47:27Z","isPatch":true,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"When debugging subprocess calls (with STGIT_SUBPROCESS_LOG=debug),\nit's important to know the environment and working directory we pass\nto the subprocess, not just the command-line parameters.\n\nSigned-off-by: Karl Hasselström <kha@treskal.com>\n\n---\n\n stgit/run.py |    6 ++++++\n 1 files changed, 6 insertions(+), 0 deletions(-)\n\n\ndiff --git a/stgit/run.py b/stgit/run.py\nindex 77f2e65..0b79729 100644\n--- a/stgit/run.py\n+++ b/stgit/run.py\n@@ -48,6 +48,12 @@ class Run:\n     def __log_start(self):\n         if _log_mode == 'debug':\n             out.start('Running subprocess %s' % self.__cmd)\n+            if self.__cwd != None:\n+                out.info('cwd: %s' % self.__cwd)\n+            if self.__env != None:\n+                for k in sorted(self.__env.iterkeys()):\n+                    if k not in os.environ or os.environ[k] != self.__env[k]:\n+                        out.info('%s: %s' % (k, self.__env[k]))\n         elif _log_mode == 'profile':\n             out.start('Running subprocess %s' % self.__cmd[0])\n             self.__starttime = datetime.datetime.now()\n"}]}