{"thread":{"id":"59977","subject":"bug report: cloning private repo to absolute path doesn't work if gitconfig has includeIf directives","startedAt":"2023-07-12T16:23:31Z","lastAt":"2023-07-13T00:22:26Z","messageCount":2,"participants":["Juan M Uys","brian m. carlson"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"479412","messageId":"CADfPAEbgfvnS6JTwa5Y1Zt7gQ31GRUyjjjpX9mmpcwxsaTLPGw@mail.gmail.com","threadId":"59977","inReplyTo":null,"subject":"bug report: cloning private repo to absolute path doesn't work if gitconfig has includeIf directives","fromName":"Juan M Uys","fromEmail":"opyate@gmail.com","sentAt":"2023-07-12T16:21:38Z","receivedAt":"2023-07-12T16:23:31Z","isPatch":false,"sender":{"key":"opyate@gmail.com","avatar":null},"body":"The entire description is in the attachment.\n\n\nThank you for filling out a Git bug report!\nPlease answer the following questions to help us understand your issue.\n\nWhat did you do before the bug happened? (Steps to reproduce your issue)\n\nWhat did you expect to happen? (Expected behavior)\n\nI want to clone a private repo to an absolute path (regardless of whether the path exists or not), and it doesn't work. E.g.\n\nWhat happened instead? (Actual behavior)\n\n```\n% git clone --depth=1 'git@github.com:myorg/myprivaterepo.git' '/tmp/some-new-folder'\nCloning into '/tmp/some-new-folder'...\nERROR: Repository not found.\nfatal: Could not read from remote repository.\n\nPlease make sure you have the correct access rights\nand the repository exists.\n```\n\nHowever, if I remove the last argument, it works, and clones to the current directory:\n\n```\n% git clone --depth=1 'git@github.com:myorg/myprivaterepo.git'\nCloning into 'myprivaterepo'...\nremote: Enumerating objects: 99, done.\nremote: Counting objects: 100% (99/99), done.\nremote: Compressing objects: 100% (87/87), done.\nremote: Total 99 (delta 7), reused 77 (delta 7), pack-reused 0\nReceiving objects: 100% (99/99), 5.66 MiB | 4.71 MiB/s, done.\nResolving deltas: 100% (7/7), done.\n```\n\nPublic repos work if I specify an absolute path as the destination directory, e.g.:\n\n```\n% git clone --depth=1 'https://github.com/git/htmldocs.git' '/tmp/git-html-docs'\nCloning into '/tmp/git-html-docs'...\nremote: Enumerating objects: 1028, done.\nremote: Counting objects: 100% (1028/1028), done.\nremote: Compressing objects: 100% (920/920), done.\nremote: Total 1028 (delta 312), reused 455 (delta 107), pack-reused 0\nReceiving objects: 100% (1028/1028), 3.24 MiB | 4.13 MiB/s, done.\nResolving deltas: 100% (312/312), done.\n```\n\nWhat's different between what you expected and what actually happened?\n\nI'm getting an \"access rights\" error, instead of my repo being cloned.\n\nAnything else you want to add:\n\nI separate my git organisations with different SSH keys with the help of a global git config:\n\n```\ninit]\n        defaultBranch = main\n[user]\n        email = opyate@gmail.com\n        name = Juan Uys\n[core]\n        excludesfile = /home/opyate/.gitignore\n        editor = vim\n        pager = less -FRX\n\n[includeIf \"gitdir:/home/opyate/Documents/code/org1/\"]\n        path = /home/opyate/Documents/code/org1/gitconfig\n[includeIf \"gitdir:/home/opyate/Documents/code/org2/\"]\n        path = /home/opyate/Documents/code/org2/gitconfig\n[filter \"lfs\"]\n        clean = git-lfs clean -- %f\n        smudge = git-lfs smudge -- %f\n        process = git-lfs filter-process\n        required = true\n```\n\nAnd then each org's gitconfig typically looks like:\n\n```\n[user]\n        name = Juan Uys\n        email = juan.uys@org1.com\n\n\n[core]\n        sshCommand = \"ssh -i ~/.ssh/org1/id_ed25519\"\n```\n\n\nPlease review the rest of the bug report below.\nYou can delete any lines you don't wish to share.\n\n\n[System Info]\ngit version:\ngit version 2.41.0\ncpu: x86_64\nno commit associated with this build\nsizeof-long: 8\nsizeof-size_t: 8\nshell-path: /bin/sh\nuname: Linux 5.15.0-76-generic #83~20.04.1-Ubuntu SMP Wed Jun 21 20:23:31 UTC 2023 x86_64\ncompiler info: gnuc: 9.4\nlibc info: glibc: 2.31\n$SHELL (typically, interactive shell): /usr/bin/zsh\n\n\n[Enabled Hooks]\nnot run from a git repository - no hooks to show\n"},{"id":"479448","messageId":"ZK9Dgqgy5qRDKhG0@tapette.crustytoothpaste.net","threadId":"59977","inReplyTo":"CADfPAEbgfvnS6JTwa5Y1Zt7gQ31GRUyjjjpX9mmpcwxsaTLPGw@mail.gmail.com","subject":"Re: bug report: cloning private repo to absolute path doesn't work if gitconfig has includeIf directives","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2023-07-13T00:21:22Z","receivedAt":"2023-07-13T00:22:26Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2023-07-12 at 16:21:38, Juan M Uys wrote:\n> What happened instead? (Actual behavior)\n> \n> ```\n> % git clone --depth=1 'git@github.com:myorg/myprivaterepo.git' '/tmp/some-new-folder'\n> Cloning into '/tmp/some-new-folder'...\n> ERROR: Repository not found.\n> fatal: Could not read from remote repository.\n> \n> Please make sure you have the correct access rights\n> and the repository exists.\n> ```\n> \n> However, if I remove the last argument, it works, and clones to the current directory:\n> \n> ```\n> % git clone --depth=1 'git@github.com:myorg/myprivaterepo.git'\n> Cloning into 'myprivaterepo'...\n> remote: Enumerating objects: 99, done.\n> remote: Counting objects: 100% (99/99), done.\n> remote: Compressing objects: 100% (87/87), done.\n> remote: Total 99 (delta 7), reused 77 (delta 7), pack-reused 0\n> Receiving objects: 100% (99/99), 5.66 MiB | 4.71 MiB/s, done.\n> Resolving deltas: 100% (7/7), done.\n> ```\n\nIs the directory you're cloning to the same as above?  Do you see the\nsame behaviour as above if you switch to /tmp and run this:\n\n  $ git clone --depth=1 'git@github.com:myorg/myprivaterepo.git' some-new-folder\n\n> I separate my git organisations with different SSH keys with the help of a global git config:\n> \n> ```\n> init]\n>         defaultBranch = main\n> [user]\n>         email = opyate@gmail.com\n>         name = Juan Uys\n> [core]\n>         excludesfile = /home/opyate/.gitignore\n>         editor = vim\n>         pager = less -FRX\n> \n> [includeIf \"gitdir:/home/opyate/Documents/code/org1/\"]\n>         path = /home/opyate/Documents/code/org1/gitconfig\n> [includeIf \"gitdir:/home/opyate/Documents/code/org2/\"]\n>         path = /home/opyate/Documents/code/org2/gitconfig\n> [filter \"lfs\"]\n>         clean = git-lfs clean -- %f\n>         smudge = git-lfs smudge -- %f\n>         process = git-lfs filter-process\n>         required = true\n> ```\n> \n> And then each org's gitconfig typically looks like:\n> \n> ```\n> [user]\n>         name = Juan Uys\n>         email = juan.uys@org1.com\n> \n> \n> [core]\n>         sshCommand = \"ssh -i ~/.ssh/org1/id_ed25519\"\n> ```\n\nMy guess is that this is related.  If you're cloning into one of the\ndirectories specified with `includeIf` above, then you'd be using a\nspecific SSH key to do so.  In such a case, you'd have access to\ndifferent things than if you cloned in a different repository.\n\nThat would explain why public repositories work: as long as you have\nan SSH key valid for _some_ account on GitHub, you can clone any public\nrepository.\n-- \nbrian m. carlson (he/him or they/them)\nToronto, Ontario, CA\n"}]}