{"thread":{"id":"17726","subject":"Git push failure in the case of SSH to localhost","startedAt":"2009-02-11T16:24:29Z","lastAt":"2009-02-11T21:03:14Z","messageCount":17,"participants":["Ciprian Dorin, Craciun","Jeff King","Shawn O. Pearce","Junio C Hamano","Johannes Schindelin"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"104206","messageId":"8e04b5820902110824u1ab99cc1r4df6349b20d62f84@mail.gmail.com","threadId":"17726","inReplyTo":null,"subject":"Git push failure in the case of SSH to localhost","fromName":"Ciprian Dorin, Craciun","fromEmail":"ciprian.craciun@gmail.com","sentAt":"2009-02-11T16:24:29Z","receivedAt":"2009-02-11T16:24:29Z","isPatch":false,"sender":{"key":"ciprian.craciun@gmail.com","avatar":"https://gravatar.com/avatar/9685eb13288a2c28bdde10acdcda9f15d495efad7b12bf49e3525eb7b8acf944?d=mp&s=160"},"body":"    Hello all!\n\n    I've encountered the following error situations: git fails to push\na branch over ssh to localhost, even with file: protocol it has the\nsame behaviour... Please see the transcript... (Git version is\n1.6.1.1) I don't think I'm doing something wrong, because this works\njust fine with a real remote host...\n\n    Thanks,\n    Ciprian Craciun.\n\n    P.S.: I'm using a slightly modified version of Git, but this patch\naffects only the PATH-like search mechanism for git commands.\n\n----\n\n    0  git version\ngit version 1.6.1.1.dirty\n\n    1  cd /tmp\n    2  mkdir r1\n    3  cd r1\n    4  git init\n    5  cd ..\n    6  mkdir r2\n    7  cd r2\n    8  git init --bare\n    9  cd ..\n   10  cd r1\n   11  echo a>a\n   12  git add .\n   13  git commit -m '--'\n\n   14  git push ssh://localhost/tmp/r2 master\nCounting objects: 3, done.\nWriting objects: 100% (3/3), 197 bytes, done.\nTotal 3 (delta 0), reused 0 (delta 0)\nerror: unpack should have generated\nea8c5601f49a4bdeea03db3adb909d590ea730d3, but I can't find it!\nTo ssh://localhost/tmp/r2\n ! [remote rejected] master -> master (bad pack)\nerror: failed to push some refs to 'ssh://localhost/tmp/r2'\n\n   15  git push file:///tmp/r2 master\nCounting objects: 3, done.\nWriting objects: 100% (3/3), 197 bytes, done.\nTotal 3 (delta 0), reused 0 (delta 0)\nerror: unpack should have generated\nea8c5601f49a4bdeea03db3adb909d590ea730d3, but I can't find it!\nTo file:///tmp/r2\n ! [remote rejected] master -> master (bad pack)\nerror: failed to push some refs to 'file:///tmp/r2'\n\n    16 git push ssh://hephaistos.tartarus./tmp/r2 master\nCounting objects: 3, done.\nWriting objects: 100% (3/3), 197 bytes, done.\nTotal 3 (delta 0), reused 0 (delta 0)\nTo ssh://dom1.hephaistos.tartarus./tmp/r2\n * [new branch]      master -> master\n"},{"id":"104233","messageId":"20090211180559.GC19749@coredump.intra.peff.net","threadId":"17726","inReplyTo":"8e04b5820902110824u1ab99cc1r4df6349b20d62f84@mail.gmail.com","subject":"Re: Git push failure in the case of SSH to localhost","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-02-11T18:05:59Z","receivedAt":"2009-02-11T18:05:59Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Feb 11, 2009 at 06:24:29PM +0200, Ciprian Dorin, Craciun wrote:\n\n>    15  git push file:///tmp/r2 master\n> Counting objects: 3, done.\n> Writing objects: 100% (3/3), 197 bytes, done.\n> Total 3 (delta 0), reused 0 (delta 0)\n> error: unpack should have generated\n> ea8c5601f49a4bdeea03db3adb909d590ea730d3, but I can't find it!\n> To file:///tmp/r2\n>  ! [remote rejected] master -> master (bad pack)\n> error: failed to push some refs to 'file:///tmp/r2'\n\nI can't reproduce the problem here. It looks like your receive-pack is\nsomehow broken (which should be the only difference between pushing to a\nlocal repo and a remote one).\n\nCan you try with a vanilla version of git to be sure it is not your\nadd-on patch responsible?\n\n-Peff\n"},{"id":"104264","messageId":"8e04b5820902111042q138a2e79vc97c533007482e5c@mail.gmail.com","threadId":"17726","inReplyTo":"20090211180559.GC19749@coredump.intra.peff.net","subject":"Re: Git push failure in the case of SSH to localhost","fromName":"Ciprian Dorin, Craciun","fromEmail":"ciprian.craciun@gmail.com","sentAt":"2009-02-11T18:42:25Z","receivedAt":"2009-02-11T18:42:25Z","isPatch":false,"sender":{"key":"ciprian.craciun@gmail.com","avatar":"https://gravatar.com/avatar/9685eb13288a2c28bdde10acdcda9f15d495efad7b12bf49e3525eb7b8acf944?d=mp&s=160"},"body":"On Wed, Feb 11, 2009 at 8:05 PM, Jeff King <peff@peff.net> wrote:\n> On Wed, Feb 11, 2009 at 06:24:29PM +0200, Ciprian Dorin, Craciun wrote:\n>\n>>    15  git push file:///tmp/r2 master\n>> Counting objects: 3, done.\n>> Writing objects: 100% (3/3), 197 bytes, done.\n>> Total 3 (delta 0), reused 0 (delta 0)\n>> error: unpack should have generated\n>> ea8c5601f49a4bdeea03db3adb909d590ea730d3, but I can't find it!\n>> To file:///tmp/r2\n>>  ! [remote rejected] master -> master (bad pack)\n>> error: failed to push some refs to 'file:///tmp/r2'\n>\n> I can't reproduce the problem here. It looks like your receive-pack is\n> somehow broken (which should be the only difference between pushing to a\n> local repo and a remote one).\n>\n> Can you try with a vanilla version of git to be sure it is not your\n> add-on patch responsible?\n>\n> -Peff\n\n    Indeed it seems it's from my patch... Because with a vanila\n1.6.1.1 it works perfectly... I'll dig into what I've done, although I\ncouldn't imagine that it was from my patch...\n\n    For now I see that the problem comes from the function\nsetup_git_directory_gentry which I call inside the setup_path function\nin exec_cmd.c\n    Can someone help? (My patch is below...)\n\n    Thanks,\n    Ciprian Craciun.\n\n--------\n\ndiff --git a/exec_cmd.c b/exec_cmd.c\nindex cdd35f9..1513ee0 100644\n--- a/exec_cmd.c\n+++ b/exec_cmd.c\n@@ -44,6 +44,44 @@ const char *git_exec_path(void)\n \treturn system_path(GIT_EXEC_PATH);\n }\n\n+/* Returns the path of the bin folder inside the .git folder. */\n+/* (This could be used to store repository specific git programs.) */\n+const char *git_repo_exec_path(void)\n+{\n+\tstatic char path_buffer[PATH_MAX + 1];\n+\tstatic char *path = NULL;\n+\t\n+\tint non_git;\n+\tconst char *git_dir;\n+\tchar cwd[PATH_MAX + 1];\n+\t\n+\tif (!path) {\n+\t\t\n+\t\tpath = path_buffer;\n+\t\tpath[0] = '\\0';\n+\t\t\n+\t\tif (!getcwd(cwd, PATH_MAX))\n+\t\t\tdie(\"git_repo_exec_path: can not getcwd\");\n+\t\t\n+\t\tsetup_git_directory_gently(&non_git);\n+\t\t\n+\t\tif (!non_git) {\n+\t\t\t\n+\t\t\tgit_dir = get_git_dir();\n+\t\t\tstrncat(path, git_dir, PATH_MAX);\n+\t\t\tstrncat(path, \"/\", PATH_MAX);\n+\t\t\tstrncat(path, \"bin\", PATH_MAX);\n+\t\t\t\n+\t\t\tstrncpy(path, make_absolute_path(path), PATH_MAX);\n+\t\t\t\n+\t\t\tif (chdir(cwd))\n+\t\t\t\tdie(\"git_repo_exec_path: can not chdir to '%s'\", cwd);\n+\t\t}\n+\t}\n+\t\n+\treturn path;\n+}\n+\n static void add_path(struct strbuf *out, const char *path)\n {\n \tif (path && *path) {\n@@ -61,6 +99,7 @@ void setup_path(void)\n \tconst char *old_path = getenv(\"PATH\");\n \tstruct strbuf new_path = STRBUF_INIT;\n\n+\tadd_path(&new_path, git_repo_exec_path());\n \tadd_path(&new_path, argv_exec_path);\n \tadd_path(&new_path, getenv(EXEC_PATH_ENVIRONMENT));\n \tadd_path(&new_path, system_path(GIT_EXEC_PATH));\n"},{"id":"104266","messageId":"20090211184429.GA27896@coredump.intra.peff.net","threadId":"17726","inReplyTo":"8e04b5820902111042q138a2e79vc97c533007482e5c@mail.gmail.com","subject":"Re: Git push failure in the case of SSH to localhost","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-02-11T18:44:29Z","receivedAt":"2009-02-11T18:44:29Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Feb 11, 2009 at 08:42:25PM +0200, Ciprian Dorin, Craciun wrote:\n\n>     For now I see that the problem comes from the function\n> setup_git_directory_gentry which I call inside the setup_path function\n> in exec_cmd.c\n\nI think you probably end up calling setup_git_directory_gently twice,\nwhich is known to have weird interactions.\n\n-Peff\n"},{"id":"104273","messageId":"8e04b5820902111103n69cde3e1le5781fb1818b622c@mail.gmail.com","threadId":"17726","inReplyTo":"20090211184429.GA27896@coredump.intra.peff.net","subject":"Re: Git push failure in the case of SSH to localhost","fromName":"Ciprian Dorin, Craciun","fromEmail":"ciprian.craciun@gmail.com","sentAt":"2009-02-11T19:03:48Z","receivedAt":"2009-02-11T19:03:48Z","isPatch":false,"sender":{"key":"ciprian.craciun@gmail.com","avatar":"https://gravatar.com/avatar/9685eb13288a2c28bdde10acdcda9f15d495efad7b12bf49e3525eb7b8acf944?d=mp&s=160"},"body":"On Wed, Feb 11, 2009 at 8:44 PM, Jeff King <peff@peff.net> wrote:\n> On Wed, Feb 11, 2009 at 08:42:25PM +0200, Ciprian Dorin, Craciun wrote:\n>\n>>     For now I see that the problem comes from the function\n>> setup_git_directory_gentry which I call inside the setup_path function\n>> in exec_cmd.c\n>\n> I think you probably end up calling setup_git_directory_gently twice,\n> which is known to have weird interactions.\n>\n> -Peff\n\n    Indeed it gets called twice...\n\n    Here is what I'm trying to accomplish: I want to add to the git\nsearch path also the folder ${GIT_DIR}/bin if this already exists...\n(This allows me to have repository specific commands...)\n\n    So in order to obtain GIT_DIR (get_git_dir function), I have to\ncall setup_git_directory_gently...\n\n    Is there another way to obtain the right GIT_DIR?\n\n    Ciprian.\n"},{"id":"104275","messageId":"20090211191445.GU30949@spearce.org","threadId":"17726","inReplyTo":"8e04b5820902111103n69cde3e1le5781fb1818b622c@mail.gmail.com","subject":"Re: Git push failure in the case of SSH to localhost","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-02-11T19:14:45Z","receivedAt":"2009-02-11T19:14:45Z","isPatch":false,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"\"Ciprian Dorin, Craciun\" <ciprian.craciun@gmail.com> wrote:\n> \n>     Here is what I'm trying to accomplish: I want to add to the git\n> search path also the folder ${GIT_DIR}/bin if this already exists...\n> (This allows me to have repository specific commands...)\n\nfor f in `cd $(git rev-parse --git-dir)/bin && ls *`; do\n  git config alias.$f '!$(git rev-parse --git-dir)/bin/'$f\ndone\n\nNo need to patch git.\n \n-- \nShawn.\n"},{"id":"104276","messageId":"8e04b5820902111120w4cb87b41sfca647a838bab43c@mail.gmail.com","threadId":"17726","inReplyTo":"20090211191445.GU30949@spearce.org","subject":"Re: Git push failure in the case of SSH to localhost","fromName":"Ciprian Dorin, Craciun","fromEmail":"ciprian.craciun@gmail.com","sentAt":"2009-02-11T19:20:51Z","receivedAt":"2009-02-11T19:20:51Z","isPatch":false,"sender":{"key":"ciprian.craciun@gmail.com","avatar":"https://gravatar.com/avatar/9685eb13288a2c28bdde10acdcda9f15d495efad7b12bf49e3525eb7b8acf944?d=mp&s=160"},"body":"On Wed, Feb 11, 2009 at 9:14 PM, Shawn O. Pearce <spearce@spearce.org> wrote:\n> \"Ciprian Dorin, Craciun\" <ciprian.craciun@gmail.com> wrote:\n>>\n>>     Here is what I'm trying to accomplish: I want to add to the git\n>> search path also the folder ${GIT_DIR}/bin if this already exists...\n>> (This allows me to have repository specific commands...)\n>\n> for f in `cd $(git rev-parse --git-dir)/bin && ls *`; do\n>  git config alias.$f '!$(git rev-parse --git-dir)/bin/'$f\n> done\n>\n> No need to patch git.\n>\n> --\n> Shawn.\n\n    :) Yes I know about the alias trick...\n\n    But I find it easier to just create a bin folder and drop my\nscripts there... (For example git-branch-import that takes a new\nbranch name and an URL and creates the branch with no ancestry and\nknows http, ftp, svn, tar.{gz,bz2}, zip, etc...)\n\n    Ciprian.\n"},{"id":"104277","messageId":"20090211192245.GA28832@coredump.intra.peff.net","threadId":"17726","inReplyTo":"8e04b5820902111120w4cb87b41sfca647a838bab43c@mail.gmail.com","subject":"Re: Git push failure in the case of SSH to localhost","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-02-11T19:22:45Z","receivedAt":"2009-02-11T19:22:45Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Feb 11, 2009 at 09:20:51PM +0200, Ciprian Dorin, Craciun wrote:\n\n>     But I find it easier to just create a bin folder and drop my\n> scripts there... (For example git-branch-import that takes a new\n> branch name and an URL and creates the branch with no ancestry and\n> knows http, ftp, svn, tar.{gz,bz2}, zip, etc...)\n\nI don't see what is per-repo about that. That is, why not put it in a\nPATH directory accessible by all repos. And if there is some\nrepo-specific data, you can have the script read it from the current\nrepo by \"git config\".\n\n-Peff\n"},{"id":"104278","messageId":"7vd4doepvb.fsf@gitster.siamese.dyndns.org","threadId":"17726","inReplyTo":"8e04b5820902111120w4cb87b41sfca647a838bab43c@mail.gmail.com","subject":"Re: Git push failure in the case of SSH to localhost","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-02-11T19:27:04Z","receivedAt":"2009-02-11T19:27:04Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Ciprian Dorin, Craciun\" <ciprian.craciun@gmail.com> writes:\n\n> On Wed, Feb 11, 2009 at 9:14 PM, Shawn O. Pearce <spearce@spearce.org> wrote:\n>> \"Ciprian Dorin, Craciun\" <ciprian.craciun@gmail.com> wrote:\n>>>\n>>>     Here is what I'm trying to accomplish: I want to add to the git\n>>> search path also the folder ${GIT_DIR}/bin if this already exists...\n>>> (This allows me to have repository specific commands...)\n>>\n>> for f in `cd $(git rev-parse --git-dir)/bin && ls *`; do\n>>  git config alias.$f '!$(git rev-parse --git-dir)/bin/'$f\n>> done\n>>\n>> No need to patch git.\n>>\n>> --\n>> Shawn.\n>\n>     :) Yes I know about the alias trick...\n>\n>     But I find it easier to just create a bin folder and drop my\n> scripts there... (For example git-branch-import that takes a new\n> branch name and an URL and creates the branch with no ancestry and\n> knows http, ftp, svn, tar.{gz,bz2}, zip, etc...)\n\nAnd why isn't it in $HOME/bin/?\n"},{"id":"104279","messageId":"8e04b5820902111132v5b7c8e14s15c6fad13b5b76a9@mail.gmail.com","threadId":"17726","inReplyTo":"20090211192245.GA28832@coredump.intra.peff.net","subject":"Re: Git push failure in the case of SSH to localhost","fromName":"Ciprian Dorin, Craciun","fromEmail":"ciprian.craciun@gmail.com","sentAt":"2009-02-11T19:32:29Z","receivedAt":"2009-02-11T19:32:29Z","isPatch":false,"sender":{"key":"ciprian.craciun@gmail.com","avatar":"https://gravatar.com/avatar/9685eb13288a2c28bdde10acdcda9f15d495efad7b12bf49e3525eb7b8acf944?d=mp&s=160"},"body":"On Wed, Feb 11, 2009 at 9:22 PM, Jeff King <peff@peff.net> wrote:\n> On Wed, Feb 11, 2009 at 09:20:51PM +0200, Ciprian Dorin, Craciun wrote:\n>\n>>     But I find it easier to just create a bin folder and drop my\n>> scripts there... (For example git-branch-import that takes a new\n>> branch name and an URL and creates the branch with no ancestry and\n>> knows http, ftp, svn, tar.{gz,bz2}, zip, etc...)\n>\n> I don't see what is per-repo about that. That is, why not put it in a\n> PATH directory accessible by all repos. And if there is some\n> repo-specific data, you can have the script read it from the current\n> repo by \"git config\".\n>\n> -Peff\n\n    Well, it is per-repo because I've left out to tell you that the\ngit-branch-import command I use to track non-git source code\ndistributions for other projects... And my command constructs the\nbranch name in a certain way...\n\n    Anyway, I don't see why it's wrong to have such a bin folder per\nrepository... Let's for a moment assume that there is a use case for\nsuch a thing, I'm wondering what is wrong with this solution from a\nGit perspective???\n\n    Ciprian.\n\n    P.S.: It seems that indeed setup_git_directory_gently (or\nsomething in the setup system) is kind of broken if I call it twice...\nSo I'm trying to solve the problem from another angle... It seems that\nsetup_paths is called only from git.c, builtin-receive-pack.c,\nupload-pack.c and shell.c... Thus I'll just work-around the problem by\nadding the bin path only when it is called from git.c (which it has\nworked for almost a year...)\n"},{"id":"104281","messageId":"8e04b5820902111134o73f0cbc9gc25aeaae9a267f9a@mail.gmail.com","threadId":"17726","inReplyTo":"7vd4doepvb.fsf@gitster.siamese.dyndns.org","subject":"Re: Git push failure in the case of SSH to localhost","fromName":"Ciprian Dorin, Craciun","fromEmail":"ciprian.craciun@gmail.com","sentAt":"2009-02-11T19:34:07Z","receivedAt":"2009-02-11T19:34:07Z","isPatch":false,"sender":{"key":"ciprian.craciun@gmail.com","avatar":"https://gravatar.com/avatar/9685eb13288a2c28bdde10acdcda9f15d495efad7b12bf49e3525eb7b8acf944?d=mp&s=160"},"body":"On Wed, Feb 11, 2009 at 9:27 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> \"Ciprian Dorin, Craciun\" <ciprian.craciun@gmail.com> writes:\n>\n>> On Wed, Feb 11, 2009 at 9:14 PM, Shawn O. Pearce <spearce@spearce.org> wrote:\n>>> \"Ciprian Dorin, Craciun\" <ciprian.craciun@gmail.com> wrote:\n>>>>\n>>>>     Here is what I'm trying to accomplish: I want to add to the git\n>>>> search path also the folder ${GIT_DIR}/bin if this already exists...\n>>>> (This allows me to have repository specific commands...)\n>>>\n>>> for f in `cd $(git rev-parse --git-dir)/bin && ls *`; do\n>>>  git config alias.$f '!$(git rev-parse --git-dir)/bin/'$f\n>>> done\n>>>\n>>> No need to patch git.\n>>>\n>>> --\n>>> Shawn.\n>>\n>>     :) Yes I know about the alias trick...\n>>\n>>     But I find it easier to just create a bin folder and drop my\n>> scripts there... (For example git-branch-import that takes a new\n>> branch name and an URL and creates the branch with no ancestry and\n>> knows http, ftp, svn, tar.{gz,bz2}, zip, etc...)\n>\n> And why isn't it in $HOME/bin/?\n\n    No, it is inside .git/bin folder. I like to think to my bin folder\nlike the hooks folder... This way when I move a repository I move the\nhooks and the specific commands.\n\n    Ciprian.\n"},{"id":"104282","messageId":"7v63jgep8u.fsf@gitster.siamese.dyndns.org","threadId":"17726","inReplyTo":"8e04b5820902111134o73f0cbc9gc25aeaae9a267f9a@mail.gmail.com","subject":"Re: Git push failure in the case of SSH to localhost","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-02-11T19:40:33Z","receivedAt":"2009-02-11T19:40:33Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Ciprian Dorin, Craciun\" <ciprian.craciun@gmail.com> writes:\n\n> On Wed, Feb 11, 2009 at 9:27 PM, Junio C Hamano <gitster@pobox.com> wrote:\n>\n>> And why isn't it in $HOME/bin/?\n>\n>     No, it is inside .git/bin folder.\n\nYou are not answering my question.\n\nI questioned the sanity of putting the scripts in .git/bin/ per\nrepository.  Why shouldn't a useful script like your \"branch-import\"\navailable to _all_ your repositories, possibly taking customization per\nrepository from repository's .git/config file, so that it does what is\nappropriate in each repository?\n"},{"id":"104285","messageId":"20090211194218.GA28927@coredump.intra.peff.net","threadId":"17726","inReplyTo":"8e04b5820902111132v5b7c8e14s15c6fad13b5b76a9@mail.gmail.com","subject":"Re: Git push failure in the case of SSH to localhost","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-02-11T19:42:18Z","receivedAt":"2009-02-11T19:42:18Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Feb 11, 2009 at 09:32:29PM +0200, Ciprian Dorin, Craciun wrote:\n\n>     Anyway, I don't see why it's wrong to have such a bin folder per\n> repository... Let's for a moment assume that there is a use case for\n> such a thing, I'm wondering what is wrong with this solution from a\n> Git perspective???\n\nIt's not _wrong_, we're just suggesting ways that the same thing might\nbe accomplished more easily.\n\n>     P.S.: It seems that indeed setup_git_directory_gently (or\n> something in the setup system) is kind of broken if I call it twice...\n\nYes, I think your patch is running into a long-standing problem in the\ngit initialization code. There are problems if you need to look into the\nrepo dir to find out which command to execute, because finding the repo\ndir changes the environment. There is a similar problem with aliases.\n\nSo I think getting your patch to run correctly may be hard. But I admit\nI didn't look at it that closely.\n\n-Peff\n"},{"id":"104288","messageId":"8e04b5820902111203t344881f6g31f25cfbff5fd822@mail.gmail.com","threadId":"17726","inReplyTo":"20090211194218.GA28927@coredump.intra.peff.net","subject":"Re: Git push failure in the case of SSH to localhost","fromName":"Ciprian Dorin, Craciun","fromEmail":"ciprian.craciun@gmail.com","sentAt":"2009-02-11T20:03:13Z","receivedAt":"2009-02-11T20:03:13Z","isPatch":false,"sender":{"key":"ciprian.craciun@gmail.com","avatar":"https://gravatar.com/avatar/9685eb13288a2c28bdde10acdcda9f15d495efad7b12bf49e3525eb7b8acf944?d=mp&s=160"},"body":"    I'll merge both Junio's and Jeff's emails into one... My answers bellow.\n\n\nOn Wed, Feb 11, 2009 at 9:40 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> \"Ciprian Dorin, Craciun\" <ciprian.craciun@gmail.com> writes:\n>\n>> On Wed, Feb 11, 2009 at 9:27 PM, Junio C Hamano <gitster@pobox.com> wrote:\n>>\n>>> And why isn't it in $HOME/bin/?\n>>\n>>     No, it is inside .git/bin folder.\n>\n> You are not answering my question.\n>\n> I questioned the sanity of putting the scripts in .git/bin/ per\n> repository.  Why shouldn't a useful script like your \"branch-import\"\n> available to _all_ your repositories, possibly taking customization per\n> repository from repository's .git/config file, so that it does what is\n> appropriate in each repository?\n\n    Indeed my problem could be solved by either of the solutions\nproposed (I'll summarize them for the sake of completeness):\n    * using git alias to put simple inline scripts (without need of a\nnew file), or to put the path to the real script;\n    * putting the new command into a directory that is referenced from PATH;\n\n    Both these solutions work fine, except one concern: when moving\nthe repository I would also want to move my scripts, and so I'm\nremaining with only one candidate: git aliases... (For example I could\nmove the repository to another machine that I haven't setup with my\nown scripts... Of course neither my solution would work, because I\nwould need a patched Git, but this could be changed if Git would have\nthis feature built-in :) )\n\n    But, there is a disadvantage with git aliases, meaning if I want a\nbigger script then I must keep in sync both config file and script\nnames... Moreover, if I use git from another folder than the work-tree\nwould the alias still work if I used relative paths? (I don't know but\nsomeone could clear this up as there is no mention about it in the\ndocumentation...)\n\n    So my proposal is very simple: make git look inside the GIT_DIR\nand see if there is a bin folder; if so add it in the front of path\n(thus overriding built-in commands??).\n\n    The advantage is that is much simpler to setup commands by just\ndropping git-something files inside .git/bin... No config editing, no\nrelative path problems...\n\n    As a conclusion, I've patched Git myself to support such a\nfeature... (See patch bellow...)\n\n    So? Having explained in detail the problem and solutions what is\n(are) yours (or others) opinions?\n\n\nOn Wed, Feb 11, 2009 at 9:42 PM, Jeff King <peff@peff.net> wrote:\n> On Wed, Feb 11, 2009 at 09:32:29PM +0200, Ciprian Dorin, Craciun wrote:\n>\n>>     Anyway, I don't see why it's wrong to have such a bin folder per\n>> repository... Let's for a moment assume that there is a use case for\n>> such a thing, I'm wondering what is wrong with this solution from a\n>> Git perspective???\n>\n> It's not _wrong_, we're just suggesting ways that the same thing might\n> be accomplished more easily.\n>\n>>     P.S.: It seems that indeed setup_git_directory_gently (or\n>> something in the setup system) is kind of broken if I call it twice...\n>\n> Yes, I think your patch is running into a long-standing problem in the\n> git initialization code. There are problems if you need to look into the\n> repo dir to find out which command to execute, because finding the repo\n> dir changes the environment. There is a similar problem with aliases.\n>\n> So I think getting your patch to run correctly may be hard. But I admit\n> I didn't look at it that closely.\n>\n> -Peff\n\n    :) I've skipped around the problem (in a non-engineering way) by\nadding a variable which enables or disables my feature... And I only\nenable it for git.c... :)\n\n\n    Thanks both Junio, Jeff and Shawn for your answers!\n    Ciprian Craciun.\n\n    P.S.: My final (working (hopefully, although tested)) patch bellow.\n\n--------\n\ndiff --git a/exec_cmd.c b/exec_cmd.c\nindex cdd35f9..8d707e1 100644\n--- a/exec_cmd.c\n+++ b/exec_cmd.c\n@@ -44,6 +44,45 @@ const char *git_exec_path(void)\n \treturn system_path(GIT_EXEC_PATH);\n }\n\n+/* Returns the path of the bin folder inside the .git folder. */\n+/* (This could be used to store repository specific git programs.) */\n+\n+int enable_git_repo_exec_path = 0;\n+\n+const char *git_repo_exec_path(void)\n+{\n+\tstatic char path_buffer[PATH_MAX + 1];\n+\tstatic char *path = NULL;\n+\t\n+\tint non_git;\n+\tconst char *git_dir;\n+\t\n+\tif (!path && enable_git_repo_exec_path) {\n+\t\t\n+\t\tpath = path_buffer;\n+\t\tpath[0] = '\\0';\n+\t\t\n+\t\tsetup_git_directory_gently(&non_git);\n+\t\t\n+\t\tif (!non_git) {\n+\t\t\t\n+\t\t\tgit_dir = get_git_dir();\n+\t\t\t\n+\t\t\tstrncat(path, git_dir, PATH_MAX);\n+\t\t\tstrncat(path, \"/\", PATH_MAX);\n+\t\t\tstrncat(path, \"bin\", PATH_MAX);\n+\t\t\tstrncpy(path, make_absolute_path(path), PATH_MAX);\n+\t\t\tif (access(path, F_OK) != 0)\n+\t\t\t\tpath[0] = '\\0';\n+\t\t}\n+\t}\n+\t\n+\tif (!path || (path[0] == '\\0'))\n+\t\treturn NULL;\n+\t\n+\treturn path;\n+}\n+\n static void add_path(struct strbuf *out, const char *path)\n {\n \tif (path && *path) {\n@@ -61,6 +100,8 @@ void setup_path(void)\n \tconst char *old_path = getenv(\"PATH\");\n \tstruct strbuf new_path = STRBUF_INIT;\n\n+\tif (git_repo_exec_path() != NULL)\n+\t\tadd_path(&new_path, git_repo_exec_path());\n \tadd_path(&new_path, argv_exec_path);\n \tadd_path(&new_path, getenv(EXEC_PATH_ENVIRONMENT));\n \tadd_path(&new_path, system_path(GIT_EXEC_PATH));\ndiff --git a/exec_cmd.h b/exec_cmd.h\nindex 594f961..a02256b 100644\n--- a/exec_cmd.h\n+++ b/exec_cmd.h\n@@ -10,4 +10,6 @@ extern int execv_git_cmd(const char **argv); /* NULL\nterminated */\n extern int execl_git_cmd(const char *cmd, ...);\n extern const char *system_path(const char *path);\n\n+extern int enable_git_repo_exec_path;\n+\n #endif /* GIT_EXEC_CMD_H */\ndiff --git a/git.c b/git.c\nindex 940a498..d312ab9 100644\n--- a/git.c\n+++ b/git.c\n@@ -477,6 +477,7 @@ int main(int argc, const char **argv)\n \t * environment, and the $(gitexecdir) from the Makefile at build\n \t * time.\n \t */\n+\tenable_git_repo_exec_path = 1;\n \tsetup_path();\n\n \twhile (1) {\n"},{"id":"104290","messageId":"7vvdrgd8pb.fsf@gitster.siamese.dyndns.org","threadId":"17726","inReplyTo":"8e04b5820902111203t344881f6g31f25cfbff5fd822@mail.gmail.com","subject":"Re: Git push failure in the case of SSH to localhost","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-02-11T20:23:12Z","receivedAt":"2009-02-11T20:23:12Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Ciprian Dorin, Craciun\" <ciprian.craciun@gmail.com> writes:\n\n>     I'll merge both Junio's and Jeff's emails into one... My answers bellow.\n>\n> On Wed, Feb 11, 2009 at 9:40 PM, Junio C Hamano <gitster@pobox.com> wrote:\n>> \"Ciprian Dorin, Craciun\" <ciprian.craciun@gmail.com> writes:\n>>\n>>> On Wed, Feb 11, 2009 at 9:27 PM, Junio C Hamano <gitster@pobox.com> wrote:\n>>>\n>>>> And why isn't it in $HOME/bin/?\n>>>\n>>>     No, it is inside .git/bin folder.\n>>\n>> You are not answering my question.\n>>\n>> I questioned the sanity of putting the scripts in .git/bin/ per\n>> repository.  Why shouldn't a useful script like your \"branch-import\"\n>> available to _all_ your repositories, possibly taking customization per\n>> repository from repository's .git/config file, so that it does what is\n>> appropriate in each repository?\n> ...\n>     Both these solutions work fine, except one concern: when moving\n> the repository I would also want to move my scripts,...\n\nDefine \"moving the repository\".  More often than not, people move their\nrepositories with \"git clone\" than \"tar cf - | tar xf -\".\n\nNo matter how you are moving it to a new location, you would want to have\na working set of \"regular environment\" you normally work in.  Why aren't\nyou moving/copying your $HOME/bin at the same time to get a more familiar\nand useful environment?  Viewed under this light, I think your \"I move my\nrepository to a new machine\" is a made up example that is not interesting\nat all, if you ask me.\n\nThere are additional security implications.  You can invite a victim to\nrun \"git diff\" in your repository which runs your .git/bin/git-diff, for\nexample.\n"},{"id":"104293","messageId":"8e04b5820902111249n5fb87ff1r3d030b008fec0c28@mail.gmail.com","threadId":"17726","inReplyTo":"7vvdrgd8pb.fsf@gitster.siamese.dyndns.org","subject":"Re: Git push failure in the case of SSH to localhost","fromName":"Ciprian Dorin, Craciun","fromEmail":"ciprian.craciun@gmail.com","sentAt":"2009-02-11T20:49:44Z","receivedAt":"2009-02-11T20:49:44Z","isPatch":false,"sender":{"key":"ciprian.craciun@gmail.com","avatar":"https://gravatar.com/avatar/9685eb13288a2c28bdde10acdcda9f15d495efad7b12bf49e3525eb7b8acf944?d=mp&s=160"},"body":"On Wed, Feb 11, 2009 at 10:23 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> \"Ciprian Dorin, Craciun\" <ciprian.craciun@gmail.com> writes:\n>\n>>     I'll merge both Junio's and Jeff's emails into one... My answers bellow.\n>>\n>> On Wed, Feb 11, 2009 at 9:40 PM, Junio C Hamano <gitster@pobox.com> wrote:\n>>> \"Ciprian Dorin, Craciun\" <ciprian.craciun@gmail.com> writes:\n>>>\n>>>> On Wed, Feb 11, 2009 at 9:27 PM, Junio C Hamano <gitster@pobox.com> wrote:\n>>>>\n>>>>> And why isn't it in $HOME/bin/?\n>>>>\n>>>>     No, it is inside .git/bin folder.\n>>>\n>>> You are not answering my question.\n>>>\n>>> I questioned the sanity of putting the scripts in .git/bin/ per\n>>> repository.  Why shouldn't a useful script like your \"branch-import\"\n>>> available to _all_ your repositories, possibly taking customization per\n>>> repository from repository's .git/config file, so that it does what is\n>>> appropriate in each repository?\n>> ...\n>>     Both these solutions work fine, except one concern: when moving\n>> the repository I would also want to move my scripts,...\n>\n> Define \"moving the repository\".  More often than not, people move their\n> repositories with \"git clone\" than \"tar cf - | tar xf -\".\n>\n> No matter how you are moving it to a new location, you would want to have\n> a working set of \"regular environment\" you normally work in.  Why aren't\n> you moving/copying your $HOME/bin at the same time to get a more familiar\n> and useful environment?  Viewed under this light, I think your \"I move my\n> repository to a new machine\" is a made up example that is not interesting\n> at all, if you ask me.\n>\n> There are additional security implications.  You can invite a victim to\n> run \"git diff\" in your repository which runs your .git/bin/git-diff, for\n> example.\n\n\n    By moving the repository I mean moving it on another machine...\nLet me give you an example...\n\n    Thus (inspired by one of my current usages of Git) suppose I'm\nworking at a scientific project (let's assume algorithmic nature) and\nafter I succeed in having a working version of my algorithm, I decide\nto test it on a better hardware with bigger workloads... For this I\nmake a tar of my repository, and un-tar it on the remote machine. (On\nthis remote machine, as I don't have administrative rights, I've\ncompiled by hand the latest version of git and put it somewhere on my\npath. But it would have been nice if I would have had the latest git\nversion already installed...)\n\n    (Looking even further, I could use such a procedure to distribute\nmy code to an entire cluster... Which I'm working to do right now...)\n\n    Where do the repository-custom commands get into the scene? Well\nlet's suppose I also want to track the run-traces of my algorithm for\nresults reproduction / debugging purposes. But these files are big\ntext files that differ in many unimportant places, and thus I would\nlike `git diff` to show me only the meaning-full differences (by using\nexternal diff feature)... Also the custom diff is not very simple (it\nneeds a couple sed / grep / other pre-processing), so I decide to\ncreate a special command (like git-diff-traces) that I put inside the\nbin folder... (Maybe I would like also some cleaning of unimportant\nlines before committing...)\n\n    (About the cluster thing, what about a command like\ngit-cluster-push... This could be reused...)\n\n    Now as you can see, the special commands that handle my traces are\nonly valid for this particular algorithm, thus for this particular\nrepository...\n\n    Now suppose I want to send a tar-ball of this repository to\nanother person, and I weren't using the special purpose bin dir, I\nwould also have to remember to send him the scripts that are in some\nother place than the repository, and also he would have to remember to\nput them into the PATH each time he wants to use them... So as you\nsee, a lot of manual labor...\n\n    The simplest way (by using my patch) is to do the following:\n    * either send a tar of the repository (that contains the bin) (of\ncourse he needs the patched version of Git);\n    * either tell him to clone the repository and run a simple command\nlike ./git-repo-initialize that would create the .git/bin folder and\nsymlink or copy the special scripts there...\n\n    About the security issue, I don't see any, if we add the bin\nfolder at the end of the search path, or just after the official\ninstallation path...\n\n    I don't think that this feature is more unsafe than the hooks system...\n\n    Ciprian Craciun.\n"},{"id":"104296","messageId":"alpine.DEB.1.00.0902112159240.10279@pacific.mpi-cbg.de","threadId":"17726","inReplyTo":"8e04b5820902111249n5fb87ff1r3d030b008fec0c28@mail.gmail.com","subject":"Re: Git push failure in the case of SSH to localhost","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2009-02-11T21:03:14Z","receivedAt":"2009-02-11T21:03:14Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Wed, 11 Feb 2009, Ciprian Dorin, Craciun wrote:\n\n>     By moving the repository I mean moving it on another machine...\n> Let me give you an example...\n> \n>     Thus (inspired by one of my current usages of Git) suppose I'm\n> working at a scientific project (let's assume algorithmic nature) and\n> after I succeed in having a working version of my algorithm, I decide\n> to test it on a better hardware with bigger workloads...\n\nAlready you showed that your workflow leaves to be desired.  You need to \nmove the repository using filesystem commands now.  Why?  Because you have \nstuff in .git/ that does not belong there, and does not get pushed or \nfetched as a consequence.\n\nIn similar cases, I followed three different options (and yes, I use all \nof them, in different repositories):\n\n- commit the scripts (that works amazingly well with Git :-)\n\n- have an independent branch for the scripts that I check out in a \n  subdirectory, or\n\n- put the scripts into a submodule right away, when they are useful for \n  more than one project.\n\nHth,\nDscho\n"}]}