{"thread":{"id":"29902","subject":"Need to set GIT_WORK_TREE when setting GIT_DIR !?","startedAt":"2012-03-09T22:51:48Z","lastAt":"2012-03-11T21:13:52Z","messageCount":7,"participants":["Frédéric Heitzmann","Junio C Hamano","Nguyen Thai Ngoc Duy","Jonathan Nieder"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"186597","messageId":"CALeToSUaPzdr=u7FfwHEtEanphVP5LZ09QdQXno52PLBTK0H-g@mail.gmail.com","threadId":"29902","inReplyTo":null,"subject":"Need to set GIT_WORK_TREE when setting GIT_DIR !?","fromName":"Frédéric Heitzmann","fromEmail":"frederic.heitzmann@gmail.com","sentAt":"2012-03-09T22:51:48Z","receivedAt":"2012-03-09T22:51:48Z","isPatch":false,"sender":{"key":"frederic.heitzmann@gmail.com","avatar":null},"body":"Hi all,\n\nI want to set GIT_DIR to another path than <project_dir>/.git.\nUnfortunately, git add or git status failed with the following error:\n\nfatal: This operation must be run in a work tree\n\nUnless I also set GIT_WORK_TREE, git status|add|stash|clean|... always fail.\n\ngit or git-config man pages does not state anything like this.\nDid I miss something ?\n\n#test-case :\n\nexport GIT_DIR=$PWD/.gita &&\ngit init\necho \"file a\" >> a.txt &&\ngit add a.txt\t\t\t#fail\ngit status \t\t\t#fail\n\nexport GIT_WORK_TREE=$PWD\ngit status\t\t\t#pass\ngit add a.txt &&\ngit commit -m'file a'\t\t#pass\n\nunset GIT_WORK_TREE\ngit status\t\t\t#fail, it does not look like some bug related to a newly\ncreated, empty repository\n\nNote: that using --git-dir instead of GIT_DIR give the same errors.\n\n--\nFred\n"},{"id":"186600","messageId":"7v4ntx4bol.fsf@alter.siamese.dyndns.org","threadId":"29902","inReplyTo":"CALeToSUaPzdr=u7FfwHEtEanphVP5LZ09QdQXno52PLBTK0H-g@mail.gmail.com","subject":"Re: Need to set GIT_WORK_TREE when setting GIT_DIR !?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-03-09T23:06:02Z","receivedAt":"2012-03-09T23:06:02Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Frédéric Heitzmann  <frederic.heitzmann@gmail.com> writes:\n\nYes, to the question on the Subject line.  But you can also say \n\n    [core] worktree = /path/to/the/work/tree\n\nin $GIT_DIR/config.  Make sure your $GIT_DIR/config does *NOT* say\nthat the repository is a bare repository.\n\n> ...\n> Note: that using --git-dir instead of GIT_DIR give the same errors.\n\nYes, that is the intended behaviour; the command line option and the\nenvironment variable should give you the same consistent effect).\n"},{"id":"186625","messageId":"4F5B55E8.4080000@gmail.com","threadId":"29902","inReplyTo":"7v4ntx4bol.fsf@alter.siamese.dyndns.org","subject":"Re: Need to set GIT_WORK_TREE when setting GIT_DIR !?","fromName":"Frédéric Heitzmann","fromEmail":"frederic.heitzmann@gmail.com","sentAt":"2012-03-10T13:23:52Z","receivedAt":"2012-03-10T13:23:52Z","isPatch":false,"sender":{"key":"frederic.heitzmann@gmail.com","avatar":null},"body":"\nLe 10/03/2012 00:06, Junio C Hamano a écrit :\n> Yes, to the question on the Subject line.  But you can also say\n>\n>      [core] worktree = /path/to/the/work/tree\n>\n> in $GIT_DIR/config.  Make sure your $GIT_DIR/config does *NOT* say\n> that the repository is a bare repository.\n\nThanks for clarification.\nHowever man git-config says :\n\n\"If --git-dir or GIT_DIR is specified but none of --work-tree, \nGIT_WORK_TREE and core.worktree is specified, the\ncurrent working directory is regarded as the top level of your working \ntree.\"\n\nSome more context on my precise problem :\nI have a project, with source files managed with git.\nI also use some Makefiles that I would like to manage with git _in a \nseparate repository_\n\n$ GIT_DIR=<project_path>/.git git add some_file.c ...\n$ GIT_DIR=<project_path>/.git_mk git add Makefile ...\n\nSetting worktree in each GIT_DIR/config will fix that but I can't figure \nout why current git implementation actually needs this.\n\n--\nFred\n"},{"id":"186626","messageId":"CACsJy8AUo3+ECdxfnyfYGA-mAtHB8KBOUrie3_Qo3cyfshZmAA@mail.gmail.com","threadId":"29902","inReplyTo":"4F5B55E8.4080000@gmail.com","subject":"Re: Need to set GIT_WORK_TREE when setting GIT_DIR !?","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2012-03-10T14:05:59Z","receivedAt":"2012-03-10T14:05:59Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"2012/3/10 Frédéric Heitzmann <frederic.heitzmann@gmail.com>:\n> However man git-config says :\n>\n> \"If --git-dir or GIT_DIR is specified but none of --work-tree, GIT_WORK_TREE\n> and core.worktree is specified, the\n> current working directory is regarded as the top level of your working\n> tree.\"\n>\n> Some more context on my precise problem :\n> I have a project, with source files managed with git.\n> I also use some Makefiles that I would like to manage with git _in a\n> separate repository_\n>\n> $ GIT_DIR=<project_path>/.git git add some_file.c ...\n> $ GIT_DIR=<project_path>/.git_mk git add Makefile ...\n>\n> Setting worktree in each GIT_DIR/config will fix that but I can't figure out\n> why current git implementation actually needs this.\n\nHistorical reason: before separate worktree feature was introduced,\ngit assumed worktree was at $GIT_DIR's parent directory. Old scripts\nmay rely on that behavior.\n-- \nDuy\n"},{"id":"186627","messageId":"20120310141119.GA11178@burratino","threadId":"29902","inReplyTo":"CALeToSUaPzdr=u7FfwHEtEanphVP5LZ09QdQXno52PLBTK0H-g@mail.gmail.com","subject":"Re: Need to set GIT_WORK_TREE when setting GIT_DIR !?","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2012-03-10T14:11:19Z","receivedAt":"2012-03-10T14:11:19Z","isPatch":false,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Hi,\n\nFrédéric Heitzmann wrote:\n\n> export GIT_DIR=$PWD/.gita &&\n> git init\n\nThis is where the recipe goes wrong.  It creates a bare repository.\nUsing vi or \"git config\" to edit its configuration to set the \"[core]\nbare\" setting to false would change that.\n\nThe git-config(1) manpage says:\n\n\tBy default a repository that ends in \"/.git\" is assumed to be\n\tnot bare (bare = false), while all other repositories are\n\tassumed to be bare (bare = true).\n\nand the logic in builtin/init-db.c seems to agree.\n\nMaybe there is a better place to document this.  Improvements\nwelcome.\n\nThanks,\nJonathan\n"},{"id":"186630","messageId":"7vsjhg17bh.fsf@alter.siamese.dyndns.org","threadId":"29902","inReplyTo":"CACsJy8AUo3+ECdxfnyfYGA-mAtHB8KBOUrie3_Qo3cyfshZmAA@mail.gmail.com","subject":"Re: Need to set GIT_WORK_TREE when setting GIT_DIR !?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-03-10T21:20:50Z","receivedAt":"2012-03-10T21:20:50Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nguyen Thai Ngoc Duy <pclouds@gmail.com> writes:\n\n> Historical reason: before separate worktree feature was introduced,\n> git assumed worktree was at $GIT_DIR's parent directory.\n\nIsn't the rule that the current directory becomes the root of the\nworking tree if you did not have GIT_WORK_TREE?\n\nIn any case, the way I read Frédéric is that the other repository's\nfiles will be accessed only from the root of the working tree, so as\nlong as the GIT_DIR/config says it is not a bare repository, it\nshould be OK.\n"},{"id":"186671","messageId":"4F5D1590.9050306@gmail.com","threadId":"29902","inReplyTo":"CALeToSV6xx=Vfw8gRbmeKWDzcHFaYvgFhMqx5cwtCYKdASJptw@mail.gmail.com","subject":"Re: Need to set GIT_WORK_TREE when setting GIT_DIR !?","fromName":"Frédéric Heitzmann","fromEmail":"frederic.heitzmann@gmail.com","sentAt":"2012-03-11T21:13:52Z","receivedAt":"2012-03-11T21:13:52Z","isPatch":false,"sender":{"key":"frederic.heitzmann@gmail.com","avatar":null},"body":"Hi all,\n\nMy initial mistake was that I unintenionnaly created a bare repo (which \nis really not what I want to do).\nIf I change that  - GIt_DIR=.gita git init --no-bare - everything runs fine.\n\nLessons learned :\n\n1/ the kind of repo  - bare or not bare - that git init creates depends \non GIT_DIR.\nThis _is_ documented - I should have read more carefully - but it is \nsurprising for someone not aware of the history of GIT_DIR, \nGIT_WORK_TREE, and so on.\nDon't know if it 's worth changing this semantic though.\nI let more experienced git hackers decide on this.\n\n2/ Calling a git command that needs a working tree (add, status, commit, \n...) in a bare repo should probably trigger a more explicit message. \nUsing the current directory if GIT_WORK_TREE is not set would actually \nhide a potential configuration problem.\n\nThanks for your help,\n--\nFred\n"}]}