{"thread":{"id":"49408","subject":"git fetch <remote> <branch> behaves weirdely when run in a worktree","startedAt":"2018-09-23T20:09:34Z","lastAt":"2018-10-04T07:01:12Z","messageCount":12,"participants":["Kaartic Sivaraam","Duy Nguyen","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"358734","messageId":"90301874969f7b11f33e504500c150a25d722ff8.camel@gmail.com","threadId":"49408","inReplyTo":null,"subject":"git fetch <remote> <branch> behaves weirdely when run in a worktree","fromName":"Kaartic Sivaraam","fromEmail":"kaartic.sivaraam@gmail.com","sentAt":"2018-09-23T20:09:26Z","receivedAt":"2018-09-23T20:09:34Z","isPatch":false,"sender":{"key":"kaartic.sivaraam@gmail.com","avatar":"https://avatars.githubusercontent.com/u/12448084?v=4"},"body":"Hi,\n\nI was actually trying to automae the building and installation of Git\nsource code to reduce my burden. I tried to automate it with the help\nof a script that runs daily via cron and a separate worktree used only\nby the build script.y run\n\nThe script typically fetches new changes for the next branch by running\nthe following in the build worktree (which is not the main worktree):\n\n   $ git fetch origin next\n\nI thought that would result in FETCH_HEAD pointing to the latest\nchanges for origin/next if the command succeeded.\n\nUnfortunately, it seems to be behaving weirdely when run in a worktree.\nIt sems to be behaving as if I ran 'git fetch origin'. To add to that\nconfusion when I run\n\n   $ cat $MAIN_WORKTREE/.git/worktrees/$BUILD_WORKTREE/FETCH_HEAD\n\nit seems to be printing the info about the remote refs once and then if\nI run it again immediately nothing is printed. If I repeat it again,\ninfo about remote refs is printed but this time the info about the\nremote refs is printed thrice. This happens randomly. Sample output:\n\n   01:23 $ cat ../git/.git/worktrees/$BUILD_WORKTREE/FETCH_HEAD \n   53f9a3e157dbbc901a02ac2c73346d375e24978c\tnot-for-merge\tbranch 'maint' of https://github.com/git/git\n150f307afc13961b0322ad0e7205a7b193368586\tnot-for-merge\tbranch 'master' of https://github.com/git/git\n01d371f741e6f0b0076d9ed942d99bdb23757eac\tnot-for-merge\tbranch 'next' of https://github.com/git/git\n7a81cbc028be113058e0b55062706ec6de62ed94\tnot-for-merge\tbranch 'pu' of https://github.com/git/git\n722746685bce03f223ed75febe312495e6c139da\tnot-for-merge\tbranch 'todo' of https://github.com/git/git\n   01:23 $ cat ../git/.git/worktrees/$BUILD_WORKTREE/FETCH_HEAD \n   01:23 $ cat ../git/.git/worktrees/$BUILD_WORKTREE/FETCH_HEAD \n   01:23 $ cat ../git/.git/worktrees/$BUILD_WORKTREE/FETCH_HEAD \n   53f9a3e157dbbc901a02ac2c73346d375e24978c\tnot-for-merge\tbranch 'maint' of https://github.com/git/git\n150f307afc13961b0322ad0e7205a7b193368586\tnot-for-merge\tbranch 'master' of https://github.com/git/git\n01d371f741e6f0b0076d9ed942d99bdb23757eac\tnot-for-merge\tbranch 'next' of https://github.com/git/git\n7a81cbc028be113058e0b55062706ec6de62ed94\tnot-for-merge\tbranch 'pu' of https://github.com/git/git\n722746685bce03f223ed75febe312495e6c139da\tnot-for-merge\tbranch 'todo' of https://github.com/git/git\n53f9a3e157dbbc901a02ac2c73346d375e24978c\tnot-for-merge\tbranch 'maint' of https://github.com/git/git\n150f307afc13961b0322ad0e7205a7b193368586\tnot-for-merge\tbranch 'master' of https://github.com/git/git\n01d371f741e6f0b0076d9ed942d99bdb23757eac\tnot-for-merge\tbranch 'next' of https://github.com/git/git\n7a81cbc028be113058e0b55062706ec6de62ed94\tnot-for-merge\tbranch 'pu' of https://github.com/git/git\n722746685bce03f223ed75febe312495e6c139da\tnot-for-merge\tbranch 'todo' of https://github.com/git/git\n53f9a3e157dbbc901a02ac2c73346d375e24978c\tnot-for-merge\tbranch 'maint' of https://github.com/git/git\n150f307afc13961b0322ad0e7205a7b193368586\tnot-for-merge\tbranch 'master' of https://github.com/git/git\n01d371f741e6f0b0076d9ed942d99bdb23757eac\tnot-for-merge\tbranch 'next' of https://github.com/git/git\n7a81cbc028be113058e0b55062706ec6de62ed94\tnot-for-merge\tbranch 'pu' of https://github.com/git/git\n722746685bce03f223ed75febe312495e6c139da\tnot-for-merge\tbranch 'todo' of https://github.com/git/git\n   01:23 $ cat ../git/.git/worktrees/$BUILD_WORKTREE/FETCH_HEAD \n   53f9a3e157dbbc901a02ac2c73346d375e24978c\tnot-for-merge\tbranch 'maint' of https://github.com/git/git\n150f307afc13961b0322ad0e7205a7b193368586\tnot-for-merge\tbranch 'master' of https://github.com/git/git\n01d371f741e6f0b0076d9ed942d99bdb23757eac\tnot-for-merge\tbranch 'next' of https://github.com/git/git\n7a81cbc028be113058e0b55062706ec6de62ed94\tnot-for-merge\tbranch 'pu' of https://github.com/git/git\n722746685bce03f223ed75febe312495e6c139da\tnot-for-merge\tbranch 'todo' of https://github.com/git/git\n\n   'git fetch <remote> <branch>' behaves correctly in the main worktree.\n\n   Why is this weirdness happening when run in other worktrees?\n\n   Why isn't 'git fetch <remote> <branch> not fetching the changes for\n   just the specified branch?\n\n   Am I missing something?\n\n   --\n   Sivaraam\n\n"},{"id":"358758","messageId":"CACsJy8D_37U+4sb7tb8KqGM=_3CRrTaZX1ZE9VqDVrYJT-AhnA@mail.gmail.com","threadId":"49408","inReplyTo":"90301874969f7b11f33e504500c150a25d722ff8.camel@gmail.com","subject":"Re: git fetch <remote> <branch> behaves weirdely when run in a worktree","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2018-09-24T15:17:00Z","receivedAt":"2018-09-24T15:17:29Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Sun, Sep 23, 2018 at 10:19 PM Kaartic Sivaraam\n<kaartic.sivaraam@gmail.com> wrote:\n>\n> Hi,\n>\n> I was actually trying to automae the building and installation of Git\n> source code to reduce my burden. I tried to automate it with the help\n> of a script that runs daily via cron and a separate worktree used only\n> by the build script.y run\n>\n> The script typically fetches new changes for the next branch by running\n> the following in the build worktree (which is not the main worktree):\n>\n>    $ git fetch origin next\n>\n> I thought that would result in FETCH_HEAD pointing to the latest\n> changes for origin/next if the command succeeded.\n>\n> Unfortunately, it seems to be behaving weirdely when run in a worktree.\n> It sems to be behaving as if I ran 'git fetch origin'. To add to that\n> confusion when I run\n> ...\n>    Why is this weirdness happening when run in other worktrees?\n>\n>    Why isn't 'git fetch <remote> <branch> not fetching the changes for\n>    just the specified branch?\n>\n>    Am I missing something?\n\nYes, some bugs. It behaves correctly for me. There must be something\nstrange that triggers this. What's your \"git worktree list\" (iow\nanything strange there, duplicate worktrees perhaps)? Also please try\n\"git fetch\" again with GIT_TRACE=1 and GIT_TRACE_SETUP=1. Hopefully we\ncould catch something with that.\n-- \nDuy\n"},{"id":"358855","messageId":"fa6d37b850177f7f2ba31c596d5986962eaf7382.camel@gmail.com","threadId":"49408","inReplyTo":"CACsJy8D_37U+4sb7tb8KqGM=_3CRrTaZX1ZE9VqDVrYJT-AhnA@mail.gmail.com","subject":"Re: git fetch <remote> <branch> behaves weirdely when run in a worktree","fromName":"Kaartic Sivaraam","fromEmail":"kaartic.sivaraam@gmail.com","sentAt":"2018-09-25T18:44:19Z","receivedAt":"2018-09-25T18:44:27Z","isPatch":false,"sender":{"key":"kaartic.sivaraam@gmail.com","avatar":"https://avatars.githubusercontent.com/u/12448084?v=4"},"body":"On Mon, 2018-09-24 at 17:17 +0200, Duy Nguyen wrote:\n> On Sun, Sep 23, 2018 at 10:19 PM Kaartic Sivaraam\n> <kaartic.sivaraam@gmail.com> wrote:\n> \n> Yes, some bugs. It behaves correctly for me. There must be something\n> strange that triggers this. What's your \"git worktree list\" (iow\n> anything strange there, duplicate worktrees perhaps)?\n\nNothing seems strange in the list.\n\n$ git worktree list\n$COMMON_ROOT/git                      01d371f741 (detached HEAD)\n$COMMON_ROOT/git-next                 cfa73bbfcb (detached HEAD)\n$COMMON_ROOT/git-next-build-automate  01d371f741 (detached HEAD)\n$COMMON_ROOT/git-pu                   363c5c06bb (detached HEAD)\n\nNote: I sanitized the path in which the git worktrees (including the\nmain worktree) is present as $COMMON_ROOT.\n\n\n>  Also please try\n> \"git fetch\" again with GIT_TRACE=1 and GIT_TRACE_SETUP=1. Hopefully we\n> could catch something with that.\n\n$ GIT_TRACE_SETUP=1 GIT_TRACE=1 git fetch origin next\n23:10:26.049785 trace.c:377             setup: git_dir: $COMMON_ROOT/git/.git/worktrees/git-next-build-automate\n23:10:26.049868 trace.c:378             setup: git_common_dir: $COMMON_ROOT/git/.git\n23:10:26.049901 trace.c:379             setup: worktree: $COMMON_ROOT/git-next-build-automate\n23:10:26.049922 trace.c:380             setup: cwd: $COMMON_ROOT/git-next-build-automate\n23:10:26.049941 trace.c:381             setup: prefix: (null)\n23:10:26.049955 git.c:415               trace: built-in: git fetch origin next\n23:10:26.051033 run-command.c:637       trace: run_command: git-remote-https origin https://github.com/git/git.git\n23:10:28.366526 run-command.c:637       trace: run_command: git rev-list --objects --stdin --not --all --quiet\n23:10:28.400979 run-command.c:637       trace: run_command: git rev-list --objects --stdin --not --all --quiet\n23:10:28.402745 trace.c:377             setup: git_dir: $COMMON_ROOT/git/.git/worktrees/git-next-build-automate\n23:10:28.402787 trace.c:378             setup: git_common_dir: $COMMON_ROOT/git/.git\n23:10:28.402793 trace.c:379             setup: worktree: $COMMON_ROOT/git-next-build-automate\n23:10:28.402798 trace.c:380             setup: cwd: $COMMON_ROOT/git-next-build-automate\n23:10:28.402802 trace.c:381             setup: prefix: (null)\n23:10:28.402815 git.c:415               trace: built-in: git rev-list --objects --stdin --not --all --quiet\nFrom https://github.com/git/git\n * branch                  next       -> FETCH_HEAD\n23:10:28.437350 run-command.c:1553      run_processes_parallel: preparing to run up to 1 tasks\n23:10:28.437481 run-command.c:1585      run_processes_parallel: done\n23:10:28.437763 run-command.c:637       trace: run_command: git gc --auto\n23:10:28.439608 trace.c:377             setup: git_dir: $COMMON_ROOT/git/.git/worktrees/git-next-build-automate\n23:10:28.439655 trace.c:378             setup: git_common_dir: $COMMON_ROOT/git/.git\n23:10:28.439667 trace.c:379             setup: worktree: $COMMON_ROOT/git-next-build-automate\n23:10:28.439677 trace.c:380             setup: cwd: $COMMON_ROOT/git-next-build-automate\n23:10:28.439687 trace.c:381             setup: prefix: (null)\n23:10:28.439699 git.c:415               trace: built-in: git gc --auto\n\nHTH,\nSivaraam\n\n"},{"id":"358876","messageId":"xmqqpnx1ntmm.fsf@gitster-ct.c.googlers.com","threadId":"49408","inReplyTo":"fa6d37b850177f7f2ba31c596d5986962eaf7382.camel@gmail.com","subject":"Re: git fetch <remote> <branch> behaves weirdely when run in a worktree","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-09-25T21:40:17Z","receivedAt":"2018-09-25T21:40:22Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Kaartic Sivaraam <kaartic.sivaraam@gmail.com> writes:\n\n>>  Also please try\n>> \"git fetch\" again with GIT_TRACE=1 and GIT_TRACE_SETUP=1. Hopefully we\n>> could catch something with that.\n>\n> $ GIT_TRACE_SETUP=1 GIT_TRACE=1 git fetch origin next\n> 23:10:26.049785 trace.c:377             setup: git_dir: $COMMON_ROOT/git/.git/worktrees/git-next-build-automate\n> ...\n> 23:10:28.402815 git.c:415               trace: built-in: git rev-list --objects --stdin --not --all --quiet\n> From https://github.com/git/git\n>  * branch                  next       -> FETCH_HEAD\n> 23:10:28.437350 run-command.c:1553      run_processes_parallel: preparing to run up to 1 tasks\n> ...\n\nThat looks like fetching only the 'next' branch and nothing else to\nme.\n\nPerhaps your script is referring to a variable whose assignment is\nmisspelled and invoking\n\n\tgit fetch $origin $branch\n\nand you are expecting the $branch variable to have string 'next' but\ndue to some bugs it is empty somehow?  That explains why sometimes\n(i.e. when $branch does not get the value you expect it to have) the\nscript fetches everything and some other times (i.e. when $branch\ndoes get the right value) the script fetches only the named branch.\n\n"},{"id":"358924","messageId":"37cf330b7d26241cd770de1c03961d4a88006293.camel@gmail.com","threadId":"49408","inReplyTo":"xmqqpnx1ntmm.fsf@gitster-ct.c.googlers.com","subject":"Re: git fetch <remote> <branch> behaves weirdely when run in a worktree","fromName":"Kaartic Sivaraam","fromEmail":"kaartic.sivaraam@gmail.com","sentAt":"2018-09-26T03:37:49Z","receivedAt":"2018-09-26T03:37:57Z","isPatch":false,"sender":{"key":"kaartic.sivaraam@gmail.com","avatar":"https://avatars.githubusercontent.com/u/12448084?v=4"},"body":"On 26 September 2018 03:10:17 GMT+05:30, Junio C Hamano <gitster@pobox.com> wrote:\n> \n> That looks like fetching only the 'next' branch and nothing else to\n> me.\n> \n\nInteresting.\n\n\n> Perhaps your script is referring to a variable whose assignment is\n> misspelled and invoking\n> \n> \tgit fetch $origin $branch\n> \n> and you are expecting the $branch variable to have string 'next' but\n> due to some bugs it is empty somehow?  That explains why sometimes\n> (i.e. when $branch does not get the value you expect it to have) the\n> script fetches everything and some other times (i.e. when $branch\n> does get the right value) the script fetches only the named branch.\n\nNoce guees but I should have made this clear. The weirdness I described\nin my initial mail happens when I run \"git fetch origin next\" manually\nin the terminal.\n\nThe script only helped me identity that there was an issue as it was\nautomatically building the wrong version of Git. It was building and\ninstalling the current 'origin/maint' when I wrote it for building\norigin/next. I could easily identify the difference as 'origin/maint'\nwas at v2.18 while 'origin/next' was at v2.19 when I notived this\nissue. Also the script doesn't depend on any variables for the branch\nname. I've hardcoded the 'next' branch into it. For the sake of\nreference, I've attached the script inline at the end of this mail.\nNote that I've sanitized the path in which the worktree exists as\n$COMMON_ROOT.\n\nI did not notice this weirdness in another PC. But, this happens in all\nthe worktrees other than the main worktree in my laptop. I'm not sure\nwhat I'm doing weirdly that might have caused this issue.\n\nI'm not sure whether I mentioned this before I'm currently using a\nmanually built version of Git. It was built from origin/next pointing\nat 01d371f741. But this also happens in Git v2.18.0 that comes via the\npacakge manager of my operating system (Debian testing).\n\n--\nSivaraam\n\n#!/bin/sh\n#\n# A script for the cron job that automatically fetches\n# updates for the 'next' branch of Git and builds and\n# installs the binary from source.\n#\n# The build succeeds only if the config.mak is present\n# in the directory with appropriate configuration.\n#\n# The binary is installed into the default location if\n# a prefix is not specified in the config.mak file.\n# Bringing the binary into use is in the hands of the user.\n# Hint: A bash alias might help.\n\nGIT_NEXT_BUILD_AUTOMATE_DIR='$COMMON_ROOT/git-next-build-automate'\nLOG_FILE=\"$GIT_NEXT_BUILD_AUTOMATE_DIR/GIT-NEXT-INSTALLATION-LOG.txt\"\nLOG_MSG_COMMON=\"installation of git 'next' build on $(date)\"\n\nif cd \"$GIT_NEXT_BUILD_AUTOMATE_DIR\"\nthen\n\t# Fetch the remote changes\n\tif git fetch origin next && git checkout -f FETCH_HEAD\n\tthen\n\t\tif make install\n\t\tthen\n\t\t\tGIT_NEXT_BUILD_STATUS=0\n\t\telse\n\t\t\tGIT_NEXT_BUILD_STATUS=1\n\t\tfi\n\telse\n\t\tGIT_NEXT_BUILD_STATUS=1\n\tfi\nelse\n\tGIT_NEXT_BUILD_STATUS=1\nfi\n\nif test $GIT_NEXT_BUILD_STATUS -eq 0\nthen\n\techo \"SUCCESS: $LOG_MSG_COMMON\" >>\"$LOG_FILE\"\nelse\n\techo \"FAILURE: $LOG_MSG_COMMON\" >>\"$LOG_FILE\"\nfi\n\n"},{"id":"358927","messageId":"39F9931A-B297-4525-A131-736B900F37AF@gmail.com","threadId":"49408","inReplyTo":"90301874969f7b11f33e504500c150a25d722ff8.camel@gmail.com","subject":"Re: git fetch <remote> <branch> behaves weirdely when run in a worktree","fromName":"Kaartic Sivaraam","fromEmail":"kaartic.sivaraam@gmail.com","sentAt":"2018-09-26T04:46:20Z","receivedAt":"2018-09-26T04:46:37Z","isPatch":false,"sender":{"key":"kaartic.sivaraam@gmail.com","avatar":"https://avatars.githubusercontent.com/u/12448084?v=4"},"body":"Hi,\n\nI just wanted make a point a little more clear. See comment inline.\n\n\nOn 24 September 2018 01:39:26 GMT+05:30, Kaartic Sivaraam <kaartic.sivaraam@gmail.com> wrote:\n> To add to that\n>confusion when I run\n>\n>   $ cat $MAIN_WORKTREE/.git/worktrees/$BUILD_WORKTREE/FETCH_HEAD\n>\n>it seems to be printing the info about the remote refs once and then if\n>I run it again immediately nothing is printed. If I repeat it again,\n>info about remote refs is printed but this time the info about the\n>remote refs is printed thrice. This happens randomly. Sample output:\n>\n>   01:23 $ cat ../git/.git/worktrees/$BUILD_WORKTREE/FETCH_HEAD \n>53f9a3e157dbbc901a02ac2c73346d375e24978c\tnot-for-merge\tbranch 'maint'\n>of https://github.com/git/git\n>150f307afc13961b0322ad0e7205a7b193368586\tnot-for-merge\tbranch 'master'\n>of https://github.com/git/git\n>01d371f741e6f0b0076d9ed942d99bdb23757eac\tnot-for-merge\tbranch 'next' of\n>https://github.com/git/git\n>7a81cbc028be113058e0b55062706ec6de62ed94\tnot-for-merge\tbranch 'pu' of\n>https://github.com/git/git\n>722746685bce03f223ed75febe312495e6c139da\tnot-for-merge\tbranch 'todo' of\n>https://github.com/git/git\n>   01:23 $ cat ../git/.git/worktrees/$BUILD_WORKTREE/FETCH_HEAD \n>   01:23 $ cat ../git/.git/worktrees/$BUILD_WORKTREE/FETCH_HEAD \n>   01:23 $ cat ../git/.git/worktrees/$BUILD_WORKTREE/FETCH_HEAD \n>53f9a3e157dbbc901a02ac2c73346d375e24978c\tnot-for-merge\tbranch 'maint'\n>of https://github.com/git/git\n>150f307afc13961b0322ad0e7205a7b193368586\tnot-for-merge\tbranch 'master'\n>of https://github.com/git/git\n>01d371f741e6f0b0076d9ed942d99bdb23757eac\tnot-for-merge\tbranch 'next' of\n>https://github.com/git/git\n>7a81cbc028be113058e0b55062706ec6de62ed94\tnot-for-merge\tbranch 'pu' of\n>https://github.com/git/git\n>722746685bce03f223ed75febe312495e6c139da\tnot-for-merge\tbranch 'todo' of\n>https://github.com/git/git\n>53f9a3e157dbbc901a02ac2c73346d375e24978c\tnot-for-merge\tbranch 'maint'\n>of https://github.com/git/git\n>150f307afc13961b0322ad0e7205a7b193368586\tnot-for-merge\tbranch 'master'\n>of https://github.com/git/git\n>01d371f741e6f0b0076d9ed942d99bdb23757eac\tnot-for-merge\tbranch 'next' of\n>https://github.com/git/git\n>7a81cbc028be113058e0b55062706ec6de62ed94\tnot-for-merge\tbranch 'pu' of\n>https://github.com/git/git\n>722746685bce03f223ed75febe312495e6c139da\tnot-for-merge\tbranch 'todo' of\n>https://github.com/git/git\n>53f9a3e157dbbc901a02ac2c73346d375e24978c\tnot-for-merge\tbranch 'maint'\n>of https://github.com/git/git\n>150f307afc13961b0322ad0e7205a7b193368586\tnot-for-merge\tbranch 'master'\n>of https://github.com/git/git\n>01d371f741e6f0b0076d9ed942d99bdb23757eac\tnot-for-merge\tbranch 'next' of\n>https://github.com/git/git\n>7a81cbc028be113058e0b55062706ec6de62ed94\tnot-for-merge\tbranch 'pu' of\n>https://github.com/git/git\n>722746685bce03f223ed75febe312495e6c139da\tnot-for-merge\tbranch 'todo' of\n>https://github.com/git/git\n>   01:23 $ cat ../git/.git/worktrees/$BUILD_WORKTREE/FETCH_HEAD \n>53f9a3e157dbbc901a02ac2c73346d375e24978c\tnot-for-merge\tbranch 'maint'\n>of https://github.com/git/git\n>150f307afc13961b0322ad0e7205a7b193368586\tnot-for-merge\tbranch 'master'\n>of https://github.com/git/git\n>01d371f741e6f0b0076d9ed942d99bdb23757eac\tnot-for-merge\tbranch 'next' of\n>https://github.com/git/git\n>7a81cbc028be113058e0b55062706ec6de62ed94\tnot-for-merge\tbranch 'pu' of\n>https://github.com/git/git\n>722746685bce03f223ed75febe312495e6c139da\tnot-for-merge\tbranch 'todo' of\n>https://github.com/git/git\n>\n\nThis is the most interesting part of the issue. I **did not** run 'git fetch ...' in between those cat commands. I was surprised by how the contents of FETCH_HEAD are changing without me spawning any git processes that might change it. Am I missing something here? As far as i could remember, there wasn't any IDE running that might automatically spawn git commands especially in that work tree. Weird.\n\n-- \nSivaraam\n\nSent from my Android device with K-9 Mail. Please excuse my brevity.\n"},{"id":"358949","messageId":"CACsJy8AScp1v+R62vXWuP-45LLLYwfSBNaZJfR02=d+2CzDqhg@mail.gmail.com","threadId":"49408","inReplyTo":"39F9931A-B297-4525-A131-736B900F37AF@gmail.com","subject":"Re: git fetch <remote> <branch> behaves weirdely when run in a worktree","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2018-09-26T15:24:14Z","receivedAt":"2018-09-26T15:24:43Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Wed, Sep 26, 2018 at 6:46 AM Kaartic Sivaraam\n<kaartic.sivaraam@gmail.com> wrote:\n> This is the most interesting part of the issue. I **did not** run 'git fetch ...' in between those cat commands. I was surprised by how the contents of FETCH_HEAD are changing without me spawning any git processes that might change it. Am I missing something here? As far as i could remember, there wasn't any IDE running that might automatically spawn git commands especially in that work tree. Weird.\n\nAnother possibility is FETCH_HEAD is somehow a symlink (or the whole\nworktrees/$BUILD_WORKTREE is a symlink) and is accidentally shared\nwith some other repos/worktrees.\n-- \nDuy\n"},{"id":"358952","messageId":"20180926160938.GA15312@duynguyen.home","threadId":"49408","inReplyTo":"CACsJy8AScp1v+R62vXWuP-45LLLYwfSBNaZJfR02=d+2CzDqhg@mail.gmail.com","subject":"Re: git fetch <remote> <branch> behaves weirdely when run in a worktree","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2018-09-26T16:09:38Z","receivedAt":"2018-09-26T16:09:45Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Wed, Sep 26, 2018 at 05:24:14PM +0200, Duy Nguyen wrote:\n> On Wed, Sep 26, 2018 at 6:46 AM Kaartic Sivaraam\n> <kaartic.sivaraam@gmail.com> wrote:\n> > This is the most interesting part of the issue. I **did not** run\n> >'git fetch ...' in between those cat commands. I was surprised by\n> >how the contents of FETCH_HEAD are changing without me spawning any\n> >git processes that might change it. Am I missing something here? As\n> >far as i could remember, there wasn't any IDE running that might\n> >automatically spawn git commands especially in that work\n> >tree. Weird.\n\nMaybe something like this could help track down that rogue \"git fetch\"\nprocess (it's definitely _some_ process writing to the wrong file; or\nsome file synchronization thingy is going on). You can log more of\ncourse, but this is where FETCH_HEAD is updated.\n\n-- 8< --\ndiff --git a/builtin/fetch.c b/builtin/fetch.c\nindex 0696abfc2a..0dfb580e92 100644\n--- a/builtin/fetch.c\n+++ b/builtin/fetch.c\n@@ -786,6 +786,13 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,\n \tif (!fp)\n \t\treturn error_errno(_(\"cannot open %s\"), filename);\n \n+\t{\n+\t\tstruct strbuf sb = STRBUF_INIT;\n+\t\tstrbuf_addf(&sb, \"( date; ls -l /proc/%d/cwd ) >>%s.log\", getpid(), filename);\n+\t\tsystem(sb.buf);\n+\t\tstrbuf_release(&sb);\n+\t}\n+\n \tif (raw_url)\n \t\turl = transport_anonymize_url(raw_url);\n \telse\n-- 8< --\n\n--\nDuy\n"},{"id":"358956","messageId":"xmqqpnx0mbos.fsf@gitster-ct.c.googlers.com","threadId":"49408","inReplyTo":"20180926160938.GA15312@duynguyen.home","subject":"Re: git fetch <remote> <branch> behaves weirdely when run in a worktree","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-09-26T17:05:23Z","receivedAt":"2018-09-26T17:05:29Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Duy Nguyen <pclouds@gmail.com> writes:\n\n> On Wed, Sep 26, 2018 at 05:24:14PM +0200, Duy Nguyen wrote:\n>> On Wed, Sep 26, 2018 at 6:46 AM Kaartic Sivaraam\n>> <kaartic.sivaraam@gmail.com> wrote:\n>> > This is the most interesting part of the issue. I **did not** run\n>> >'git fetch ...' in between those cat commands. I was surprised by\n>> >how the contents of FETCH_HEAD are changing without me spawning any\n>> >git processes that might change it. Am I missing something here? As\n>> >far as i could remember, there wasn't any IDE running that might\n>> >automatically spawn git commands especially in that work\n>> >tree. Weird.\n>\n> Maybe something like this could help track down that rogue \"git fetch\"\n> process (it's definitely _some_ process writing to the wrong file; or\n> some file synchronization thingy is going on). You can log more of\n> course, but this is where FETCH_HEAD is updated.\n\nWell, a background-ish thing could be some vendor-provided copy of\nGit that has nothing to do with what Kaartic would be compiling with\nthis patch X-<.\n\n> -- 8< --\n> diff --git a/builtin/fetch.c b/builtin/fetch.c\n> index 0696abfc2a..0dfb580e92 100644\n> --- a/builtin/fetch.c\n> +++ b/builtin/fetch.c\n> @@ -786,6 +786,13 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,\n>  \tif (!fp)\n>  \t\treturn error_errno(_(\"cannot open %s\"), filename);\n>  \n> +\t{\n> +\t\tstruct strbuf sb = STRBUF_INIT;\n> +\t\tstrbuf_addf(&sb, \"( date; ls -l /proc/%d/cwd ) >>%s.log\", getpid(), filename);\n> +\t\tsystem(sb.buf);\n> +\t\tstrbuf_release(&sb);\n> +\t}\n> +\n>  \tif (raw_url)\n>  \t\turl = transport_anonymize_url(raw_url);\n>  \telse\n> -- 8< --\n>\n> --\n> Duy\n"},{"id":"359442","messageId":"d876e0af6a860621ae80fde71069c5e2e6a71878.camel@gmail.com","threadId":"49408","inReplyTo":"xmqqpnx0mbos.fsf@gitster-ct.c.googlers.com","subject":"Re: git fetch <remote> <branch> behaves weirdely when run in a worktree","fromName":"Kaartic Sivaraam","fromEmail":"kaartic.sivaraam@gmail.com","sentAt":"2018-10-02T18:43:06Z","receivedAt":"2018-10-02T18:43:17Z","isPatch":false,"sender":{"key":"kaartic.sivaraam@gmail.com","avatar":"https://avatars.githubusercontent.com/u/12448084?v=4"},"body":"Hi,\n\nSorry for the delay. Got a little busy over the weekend. I seem to have\nfound the reason behind the issue in the mean time :-)\n\n\nOn Wed, 2018-09-26 at 10:05 -0700, Junio C Hamano wrote:\n> Duy Nguyen <pclouds@gmail.com> writes:\n> \n> > On Wed, Sep 26, 2018 at 05:24:14PM +0200, Duy Nguyen wrote:\n> > > On Wed, Sep 26, 2018 at 6:46 AM Kaartic Sivaraam\n> > > <kaartic.sivaraam@gmail.com> wrote:\n> > > > This is the most interesting part of the issue. I **did not** run\n> > > > 'git fetch ...' in between those cat commands. I was surprised by\n> > > > how the contents of FETCH_HEAD are changing without me spawning any\n> > > > git processes that might change it. Am I missing something here? As\n> > > > far as i could remember, there wasn't any IDE running that might\n> > > > automatically spawn git commands especially in that work\n> > > > tree. Weird.\n> > \n> > Maybe something like this could help track down that rogue \"git fetch\"\n> > process (it's definitely _some_ process writing to the wrong file; or\n> > some file synchronization thingy is going on). You can log more of\n> > course, but this is where FETCH_HEAD is updated.\n> \n\nThanks for the patch! It really helped me identify the issue.\n\nThe actual culprit here doesn't seem to be Git itself. It was the \"git-\nprompt\" bash plug-in[1] I was using. It seems to be spawning \"git\nfetch\" for every command I type on shell. That answers why the\nFETCH_HEAD was being updated even though I wasn't explicitly running\nit. The git bash plug-in seems to be fetching changes for *all* the\nupstream branches. That answers why there FETCH_HEAD was populated with\ninfo about all the branches when I explicitly requested for the next\nbranch. I've also verified that `git fetch origin next` works as\nintended (FETCH_HEAD has info only about orgin/next) when I turn-off\nthe plug-in which confirms that it's the culprit. A cursory search\nfound me a related issue[2] but I'm not sure if it's the exact same\none.\n\nI could identify the culprit only with the help of Duy's patch. Thanks\nDuy! Sorry for not realising this earlier. I almost forgot I'm using it\nas I've been accustomed to it a lot.\n\n\n> Well, a background-ish thing could be some vendor-provided copy of\n> Git that has nothing to do with what Kaartic would be compiling with\n> this patch X-<.\n\nFortunately, it wasn't the case here as the plug-in was using my\nmanually-built version of Git :-)\n\nThanks for the help!\n\nTag-line: Sometimes tools become part of our workflow so much that we\nreally don't realise their presence. It's an indication of a good tool\nbut we should be aware of suspecting them when an issue arises!\nSomething which I should have done to realise the issue ealier x-<\n\n\nReferences:\n[1]: https://github.com/magicmonty/bash-git-prompt\n[2]: https://github.com/magicmonty/bash-git-prompt/issues/125\n\nThanks,\nSivaraam\n\n"},{"id":"359607","messageId":"3F40923F-B596-403C-900D-6F411A0D1CE1@gmail.com","threadId":"49408","inReplyTo":"d876e0af6a860621ae80fde71069c5e2e6a71878.camel@gmail.com","subject":"Re: git fetch <remote> <branch> behaves weirdely when run in a worktree","fromName":"Kaartic Sivaraam","fromEmail":"kaartic.sivaraam@gmail.com","sentAt":"2018-10-04T06:54:57Z","receivedAt":"2018-10-04T06:55:09Z","isPatch":false,"sender":{"key":"kaartic.sivaraam@gmail.com","avatar":"https://avatars.githubusercontent.com/u/12448084?v=4"},"body":"\n\nOn 3 October 2018 00:13:06 GMT+05:30, Kaartic Sivaraam <kaartic.sivaraam@gmail.com> wrote:\n>Hi,\n>\n>Sorry for the delay. Got a little busy over the weekend. I seem to have\n>found the reason behind the issue in the mean time :-)\n>\n\nOops, I forgot to mention there's more comments inline!\n\nBTW, is there an issue if .git/HEAD and .git/index are owned by root? The owners seem to have changed since I created the worktree possibly due to the cron job. Just wondering if it might cause some issues.\n\n\n>On Wed, 2018-09-26 at 10:05 -0700, Junio C Hamano wrote:\n>> Duy Nguyen <pclouds@gmail.com> writes:\n>> \n>> > On Wed, Sep 26, 2018 at 05:24:14PM +0200, Duy Nguyen wrote:\n>> > > On Wed, Sep 26, 2018 at 6:46 AM Kaartic Sivaraam\n>> > > <kaartic.sivaraam@gmail.com> wrote:\n>> > > > This is the most interesting part of the issue. I **did not**\n>run\n>> > > > 'git fetch ...' in between those cat commands. I was surprised\n>by\n>> > > > how the contents of FETCH_HEAD are changing without me spawning\n>any\n>> > > > git processes that might change it. Am I missing something\n>here? As\n>> > > > far as i could remember, there wasn't any IDE running that\n>might\n>> > > > automatically spawn git commands especially in that work\n>> > > > tree. Weird.\n>> > \n>> > Maybe something like this could help track down that rogue \"git\n>fetch\"\n>> > process (it's definitely _some_ process writing to the wrong file;\n>or\n>> > some file synchronization thingy is going on). You can log more of\n>> > course, but this is where FETCH_HEAD is updated.\n>> \n>\n>Thanks for the patch! It really helped me identify the issue.\n>\n>The actual culprit here doesn't seem to be Git itself. It was the \"git-\n>prompt\" bash plug-in[1] I was using. It seems to be spawning \"git\n>fetch\" for every command I type on shell. That answers why the\n>FETCH_HEAD was being updated even though I wasn't explicitly running\n>it. The git bash plug-in seems to be fetching changes for *all* the\n>upstream branches. That answers why there FETCH_HEAD was populated with\n>info about all the branches when I explicitly requested for the next\n>branch. I've also verified that `git fetch origin next` works as\n>intended (FETCH_HEAD has info only about orgin/next) when I turn-off\n>the plug-in which confirms that it's the culprit. A cursory search\n>found me a related issue[2] but I'm not sure if it's the exact same\n>one.\n>\n>I could identify the culprit only with the help of Duy's patch. Thanks\n>Duy! Sorry for not realising this earlier. I almost forgot I'm using it\n>as I've been accustomed to it a lot.\n>\n>\n>> Well, a background-ish thing could be some vendor-provided copy of\n>> Git that has nothing to do with what Kaartic would be compiling with\n>> this patch X-<.\n>\n>Fortunately, it wasn't the case here as the plug-in was using my\n>manually-built version of Git :-)\n>\n>Thanks for the help!\n>\n>Tag-line: Sometimes tools become part of our workflow so much that we\n>really don't realise their presence. It's an indication of a good tool\n>but we should be aware of suspecting them when an issue arises!\n>Something which I should have done to realise the issue ealier x-<\n>\n>\n>References:\n>[1]: https://github.com/magicmonty/bash-git-prompt\n>[2]: https://github.com/magicmonty/bash-git-prompt/issues/125\n>\n>Thanks,\n>Sivaraam\n\n-- \nSivaraam\n\nSent from my Android device with K-9 Mail. Please excuse my brevity.\n"},{"id":"359608","messageId":"CACsJy8Ck8wnGFA2RT_fALHUe0mRO1fAOX9JpmSf6BH949ej=sw@mail.gmail.com","threadId":"49408","inReplyTo":"3F40923F-B596-403C-900D-6F411A0D1CE1@gmail.com","subject":"Re: git fetch <remote> <branch> behaves weirdely when run in a worktree","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2018-10-04T07:00:43Z","receivedAt":"2018-10-04T07:01:12Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Thu, Oct 4, 2018 at 8:55 AM Kaartic Sivaraam\n<kaartic.sivaraam@gmail.com> wrote:\n>\n>\n>\n> On 3 October 2018 00:13:06 GMT+05:30, Kaartic Sivaraam <kaartic.sivaraam@gmail.com> wrote:\n> >Hi,\n> >\n> >Sorry for the delay. Got a little busy over the weekend. I seem to have\n> >found the reason behind the issue in the mean time :-)\n> >\n>\n> Oops, I forgot to mention there's more comments inline!\n>\n> BTW, is there an issue if .git/HEAD and .git/index are owned by root? The owners seem to have changed since I created the worktree possibly due to the cron job. Just wondering if it might cause some issues.\n\nIf the files are still readable by normal user and $GIT_DIR has\npermission to delete/rename them, then I think everything still works.\n-- \nDuy\n"}]}