{"thread":{"id":"24391","subject":"git rebase does not understand --work-tree","startedAt":"2010-07-14T09:04:46Z","lastAt":"2010-07-14T12:55:21Z","messageCount":3,"participants":["Alexander Gladysh","Michael J Gruber"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"145521","messageId":"AANLkTimnk6tflv9ZZCydlX1la35GjsRfvjgTk44uDFbO@mail.gmail.com","threadId":"24391","inReplyTo":null,"subject":"git rebase does not understand --work-tree","fromName":"Alexander Gladysh","fromEmail":"agladysh@gmail.com","sentAt":"2010-07-14T09:04:46Z","receivedAt":"2010-07-14T09:04:46Z","isPatch":false,"sender":{"key":"agladysh@gmail.com","avatar":"https://avatars.githubusercontent.com/u/38239?v=4"},"body":"Hi, list!\n\n$ git --version\ngit version 1.7.1.1\n\nI often use --work-tree and --git-dir to avoid doing cd in my scripts.\n\nHowever, I've found that git rebase does not understand --work-tree\noption (see test below). Is this fixable?\n\nThanks,\nAlexander.\n\nmkdir tmp\ncd tmp\ngit init\necho \"test\">file.txt\ngit add .\ngit commit -m \"initial commit\"\n\ngit checkout -b other-branch\necho \"test2\">otherfile.txt\ngit add .\ngit commit -m \"second commit\"\n\ncd ..\ngit --git-dir=tmp/.git --work-tree=tmp rebase other-branch\n\nfatal: /usr/local/libexec/git-core/git-rebase cannot be used without a\nworking tree.\n"},{"id":"145532","messageId":"4C3DB396.2040109@drmicha.warpmail.net","threadId":"24391","inReplyTo":"AANLkTimnk6tflv9ZZCydlX1la35GjsRfvjgTk44uDFbO@mail.gmail.com","subject":"Re: git rebase does not understand --work-tree","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2010-07-14T12:54:46Z","receivedAt":"2010-07-14T12:54:46Z","isPatch":false,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Alexander Gladysh venit, vidit, dixit 14.07.2010 11:04:\n> Hi, list!\n> \n> $ git --version\n> git version 1.7.1.1\n> \n> I often use --work-tree and --git-dir to avoid doing cd in my scripts.\n> \n> However, I've found that git rebase does not understand --work-tree\n> option (see test below). Is this fixable?\n> \n> Thanks,\n> Alexander.\n\nIn your case, omitting --work-tree almost works, as well as using\n\"--work-tree=.\" (note the dot). \"Almost\" meaning that rebase does not\ncomplain. It just doesn't find the work-tree.\n\nI think the main problem here is a problem with relative work trees.\n\nFirst of all, work tree is meant to be relative to (the repo specified\nby) GIT_DIR, but that's not what \"git rev-parse --top-level\" is doing.\nExperimenting with relative --git-dir and --work-tree here shows that\nit's relative to cwd.\n\nSecond, several git shell commands (such as rebase) cd to the toplevel\nof the repo only after checking whether we are in a work tree already.\nThis is brain dead and should be cured by the upcoming patch. With that,\nabsolute paths for work-tree will work with rebase.\n\nThird, git's setup code exports GIT_DIR as an absolute path but\nGIT_WORK_TREE as a relative path. Together with the fact that the work\ntree is interpreted relative to the current directory, this is doomed\nfor failure when you cd around - as rebase does automatically!\n\nI'm not sure I find time for the latter point, but until then the patch\nenables you to work with absolute paths.\n\nMichael\n"},{"id":"145534","messageId":"96abf622ca2cf92998ce4ed393ccaa75d95dd9a8.1279112025.git.git@drmicha.warpmail.net","threadId":"24391","inReplyTo":"4C3DB396.2040109@drmicha.warpmail.net","subject":"[RFC/PATCH] am/pull/rebase/stash: cd_to_toplevel before require_work_tree","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2010-07-14T12:55:21Z","receivedAt":"2010-07-14T12:55:21Z","isPatch":true,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Currently, \"cd_to_toplevel\" comes right after \"require_work_tree\" for\nthese commands.\n\nPut \"cd_to_toplevel\" before \"require_work_tree\" so that these commands\ndo not die fatally when called with --work-tree or GIT_WORK_TREE\nproperly set from outside of the work tree.\n\nSigned-off-by: Michael J Gruber <git@drmicha.warpmail.net>\n---\n git-am.sh     |    2 +-\n git-pull.sh   |    2 +-\n git-rebase.sh |    2 +-\n git-stash.sh  |    2 +-\n 4 files changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/git-am.sh b/git-am.sh\nindex e7f008c..bf81030 100755\n--- a/git-am.sh\n+++ b/git-am.sh\n@@ -39,8 +39,8 @@ rebasing*       (internal use for git-rebase)\"\n . git-sh-setup\n prefix=$(git rev-parse --show-prefix)\n set_reflog_action am\n-require_work_tree\n cd_to_toplevel\n+require_work_tree\n \n git var GIT_COMMITTER_IDENT >/dev/null ||\n \tdie \"You need to set your committer info first\"\ndiff --git a/git-pull.sh b/git-pull.sh\nindex a09a44e..83c25b9 100755\n--- a/git-pull.sh\n+++ b/git-pull.sh\n@@ -10,8 +10,8 @@ SUBDIRECTORY_OK=Yes\n OPTIONS_SPEC=\n . git-sh-setup\n set_reflog_action \"pull $*\"\n-require_work_tree\n cd_to_toplevel\n+require_work_tree\n \n \n die_conflict () {\ndiff --git a/git-rebase.sh b/git-rebase.sh\nindex ab4afa7..96dd34f 100755\n--- a/git-rebase.sh\n+++ b/git-rebase.sh\n@@ -31,8 +31,8 @@ SUBDIRECTORY_OK=Yes\n OPTIONS_SPEC=\n . git-sh-setup\n set_reflog_action rebase\n-require_work_tree\n cd_to_toplevel\n+require_work_tree\n \n LF='\n '\ndiff --git a/git-stash.sh b/git-stash.sh\nindex 1d95447..4564892 100755\n--- a/git-stash.sh\n+++ b/git-stash.sh\n@@ -13,8 +13,8 @@ USAGE=\"list [<options>]\n SUBDIRECTORY_OK=Yes\n OPTIONS_SPEC=\n . git-sh-setup\n-require_work_tree\n cd_to_toplevel\n+require_work_tree\n \n TMP=\"$GIT_DIR/.git-stash.$$\"\n trap 'rm -f \"$TMP-*\"' 0\n-- \n1.7.2.rc1.212.g850a\n"}]}