{"thread":{"id":"60866","subject":"[RFH] \"git -C there add foo\" completes, s/add/diff/ does not","startedAt":"2024-02-07T18:35:07Z","lastAt":"2024-02-08T06:04:43Z","messageCount":3,"participants":["Junio C Hamano","Kyle Lippincott"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"488167","messageId":"xmqqcyt89l7z.fsf@gitster.g","threadId":"60866","inReplyTo":null,"subject":"[RFH] \"git -C there add foo\" completes, s/add/diff/ does not","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-02-07T18:34:56Z","receivedAt":"2024-02-07T18:35:07Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"As some of you may already know, I keep an untracked directory\ncalled \"Meta\" at the top-level of the working tree of the Git\nsource tree.  This \"Meta\" directory is actually a single-branch\nclone of the git.kernel.org/pub/scm/git/git.git that checks out\nits \"todo\" branch, where files like whats-cooking.txt lives.\n\nSo, what I often would do is\n\n    $ git -C Meta add whats-cooking.txt\n\nafter updating the draft of the next issue of the \"What's cooking\"\nreport.  The command line completion support for \"git add\" knows how\nto complete this when I stopped typing the above after whats-\" and\nhit <TAB>.  It seems that __git_find_repo_path helper function that\nnotices \"-C there\" and discovers the $GIT_DIR, and _git_add helper\nuses __git_complete_index_file that honors the discovered $GIT_DIR\nto find paths in the correct index, which is wonderful.\n\nBut the same does not work for the step before I can decide to\nactually \"add\" the contents, which is to \"diff\", i.e.\n\n    $ git -C Meta diff whats-<TAB>\n\ndoes not complete.\n\nAnybody wants to take a crack at it?\n\nThanks.\n\n"},{"id":"488203","messageId":"CAO_smVjnknv1ePTHhDNKK=C_iEg6+T0nNwaXqA67QuPd6tBkxw@mail.gmail.com","threadId":"60866","inReplyTo":"xmqqcyt89l7z.fsf@gitster.g","subject":"Re: [RFH] \"git -C there add foo\" completes, s/add/diff/ does not","fromName":"Kyle Lippincott","fromEmail":"spectral@google.com","sentAt":"2024-02-08T02:50:02Z","receivedAt":"2024-02-08T02:50:19Z","isPatch":false,"sender":{"key":"spectral@google.com","avatar":"https://avatars.githubusercontent.com/u/6371650?v=4"},"body":"On Wed, Feb 7, 2024 at 10:35 AM Junio C Hamano <gitster@pobox.com> wrote:\n>\n> As some of you may already know, I keep an untracked directory\n> called \"Meta\" at the top-level of the working tree of the Git\n> source tree.  This \"Meta\" directory is actually a single-branch\n> clone of the git.kernel.org/pub/scm/git/git.git that checks out\n> its \"todo\" branch, where files like whats-cooking.txt lives.\n>\n> So, what I often would do is\n>\n>     $ git -C Meta add whats-cooking.txt\n>\n> after updating the draft of the next issue of the \"What's cooking\"\n> report.  The command line completion support for \"git add\" knows how\n> to complete this when I stopped typing the above after whats-\" and\n> hit <TAB>.  It seems that __git_find_repo_path helper function that\n> notices \"-C there\" and discovers the $GIT_DIR, and _git_add helper\n> uses __git_complete_index_file that honors the discovered $GIT_DIR\n> to find paths in the correct index, which is wonderful.\n>\n> But the same does not work for the step before I can decide to\n> actually \"add\" the contents, which is to \"diff\", i.e.\n>\n>     $ git -C Meta diff whats-<TAB>\n>\n> does not complete.\n\nI'm not a completions expert, but I think what's happening is that the\ncompletions for `git diff` aren't producing anything, so it (where\n\"it\" here might be the shell?) falls back to just doing normal path\ncompletion. For `git add`, it's checking the `git status` output to\nfilter the list to things that need to be added, so it respects the\n`-C` option when calling into git to get that list, but there's no\nsuch logic for `git diff` (the git-specific logic treats the\n[optional] positional argument as a ref, not a file).\n\n>\n> Anybody wants to take a crack at it?\n>\n> Thanks.\n>\n>\n"},{"id":"488209","messageId":"xmqqmssbpk3r.fsf@gitster.g","threadId":"60866","inReplyTo":"CAO_smVjnknv1ePTHhDNKK=C_iEg6+T0nNwaXqA67QuPd6tBkxw@mail.gmail.com","subject":"Re: [RFH] \"git -C there add foo\" completes, s/add/diff/ does not","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-02-08T06:04:40Z","receivedAt":"2024-02-08T06:04:43Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Kyle Lippincott <spectral@google.com> writes:\n\n>> ...\n>> But the same does not work for the step before I can decide to\n>> actually \"add\" the contents, which is to \"diff\", i.e.\n>>\n>>     $ git -C Meta diff whats-<TAB>\n>>\n>> does not complete.\n>\n> I'm not a completions expert, but I think what's happening is that the\n> completions for `git diff` aren't producing anything, so it (where\n> \"it\" here might be the shell?) falls back to just doing normal path\n> completion.\n\nYes, that seems to be the case.\n\n> For `git add`, it's checking the `git status` output to\n> filter the list to things that need to be added,...\n\nNot exactly, but a close enough description, I think.\n\n__git_complete_index_file does not run `git status` but asks\nls-files the paths it knows about (including \"--others\" so that a\npath that is untracked can become a candidate to be added), then\nmassages the list of paths with a custom awk script.\n\nFor \"git diff\", depending on what two sets of contents are being\ncompared, the source of possible paths may differ, but the list of\npaths obtained from ls-files (without --others) would be appropriate\nwhen comparing the index and the working tree files, or comparing a\ntree-ish and the working tree files.  The necessary ingredient to do\nso may be pretty much the same as what is used by _git_add completion.\n\nWhen comparing two tree-ishes, the candidate would ideally come from\nunion of paths in these two tree-ishes, but I offhand do not know if\nthere already is a support for choosing from such a set.\n\nThanks.\n\n"}]}