{"thread":{"id":"26585","subject":"[PATCH] completion: complete \"git diff ...branc<TAB>\"","startedAt":"2011-02-23T21:43:08Z","lastAt":"2011-03-10T19:30:47Z","messageCount":9,"participants":["Junio C Hamano","Michael J Gruber","SZEDER Gábor"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"162059","messageId":"7vlj1677gz.fsf@alter.siamese.dyndns.org","threadId":"26585","inReplyTo":null,"subject":"[PATCH] completion: complete \"git diff ...branc<TAB>\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-02-23T21:43:08Z","receivedAt":"2011-02-23T21:43:08Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"While doing a final sanity check before merging a topic Bsomething, it is\na good idea to review what damage Bsomething branch would make, by running:\n\n    $ git diff ...Bsomething\n\nI however find myself often typing \"git diff ...B<TAB>\", seeing nothing\nhappening and then repeatedly hitting <TAB>, saying \"huh? <TAAAAAAAAB>!\".\n\nThis change would hopefully help me, and others like me.\n\nEven though there is no point in supporting \"git diff A..B\" (you can say\n\"git diff A B\" just fine), but reusing complete-revlist was the easiest\nand that form is supported as a benign but not so useful side effect.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n\n * I sent this out a while ago and have been using it ever since, but\n   totally forgot about it.  Likes, dislikes, alternatives?\n\n contrib/completion/git-completion.bash |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 64341d5..cf56514 100755\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -1137,7 +1137,7 @@ _git_diff ()\n \t\treturn\n \t\t;;\n \tesac\n-\t__git_complete_file\n+\t__git_complete_revlist\n }\n \n __git_mergetools_common=\"diffuse ecmerge emerge kdiff3 meld opendiff\n"},{"id":"162133","messageId":"4D664E19.5080804@drmicha.warpmail.net","threadId":"26585","inReplyTo":"7vlj1677gz.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] completion: complete \"git diff ...branc<TAB>\"","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2011-02-24T12:24:57Z","receivedAt":"2011-02-24T12:24:57Z","isPatch":true,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Junio C Hamano venit, vidit, dixit 23.02.2011 22:43:\n> While doing a final sanity check before merging a topic Bsomething, it is\n> a good idea to review what damage Bsomething branch would make, by running:\n> \n>     $ git diff ...Bsomething\n> \n> I however find myself often typing \"git diff ...B<TAB>\", seeing nothing\n> happening and then repeatedly hitting <TAB>, saying \"huh? <TAAAAAAAAB>!\".\n> \n> This change would hopefully help me, and others like me.\n> \n> Even though there is no point in supporting \"git diff A..B\" (you can say\n> \"git diff A B\" just fine), but reusing complete-revlist was the easiest\n> and that form is supported as a benign but not so useful side effect.\n> \n> Signed-off-by: Junio C Hamano <gitster@pobox.com>\n> ---\n> \n>  * I sent this out a while ago and have been using it ever since, but\n>    totally forgot about it.  Likes, dislikes, alternatives?\n\nLikes\n\nReminds me fo the following: Typing\n\ngit log origin/next@{1}..o<TAB>\n\ngives\n\ngit log origin/next{1}..o\n\nWTF? Completion eats at babies!\n\nMichael\n"},{"id":"162136","messageId":"20110224135821.GA14720@neumann","threadId":"26585","inReplyTo":"4D664E19.5080804@drmicha.warpmail.net","subject":"Re: [PATCH] completion: complete \"git diff ...branc<TAB>\"","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2011-02-24T13:58:21Z","receivedAt":"2011-02-24T13:58:21Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Thu, Feb 24, 2011 at 01:24:57PM +0100, Michael J Gruber wrote:\n> Reminds me fo the following: Typing\n> \n> git log origin/next@{1}..o<TAB>\n> \n> gives\n> \n> git log origin/next{1}..o\n> \n> WTF? Completion eats at babies!\n\nInteresting, I can't seem to be able to reproduce.\n\n  git log origin/next@{1}..o<TAB>\n\ngives me\n\n  git log origin/next@{1}..origin/\n\nand a TAB after that gives me all the remote branches from origin, as\nit is supposed to, leaving the @{1} intact.\n\nWhich git, bash, and bash completion versions are you using?\n\n\nBest,\nGábor\n"},{"id":"162139","messageId":"4D666625.70608@drmicha.warpmail.net","threadId":"26585","inReplyTo":"20110224135821.GA14720@neumann","subject":"Re: [PATCH] completion: complete \"git diff ...branc<TAB>\"","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2011-02-24T14:07:33Z","receivedAt":"2011-02-24T14:07:33Z","isPatch":true,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"SZEDER Gábor venit, vidit, dixit 24.02.2011 14:58:\n> On Thu, Feb 24, 2011 at 01:24:57PM +0100, Michael J Gruber wrote:\n>> Reminds me fo the following: Typing\n>>\n>> git log origin/next@{1}..o<TAB>\n>>\n>> gives\n>>\n>> git log origin/next{1}..o\n>>\n>> WTF? Completion eats at babies!\n> \n> Interesting, I can't seem to be able to reproduce.\n> \n>   git log origin/next@{1}..o<TAB>\n> \n> gives me\n> \n>   git log origin/next@{1}..origin/\n> \n> and a TAB after that gives me all the remote branches from origin, as\n> it is supposed to, leaving the @{1} intact.\n> \n> Which git, bash, and bash completion versions are you using?\n\ngit version 1.7.4.1.224.gefc87\n(yesterday's next, but I've been observing this for a while now)\n\nGNU bash, Version 4.1.7(1)-release (x86_64-redhat-linux-gnu)\n(Fedora 14+updates)\n\ngit-completion from next a few days ago\n\n(Also, I just tried with LANG=C, so it's not the de_DE locale nor utf8.)\n\nMichael\n"},{"id":"162154","messageId":"20110224151328.GB14720@neumann","threadId":"26585","inReplyTo":"7vlj1677gz.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] completion: complete \"git diff ...branc<TAB>\"","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2011-02-24T15:13:28Z","receivedAt":"2011-02-24T15:13:28Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"Hi,\n\n\nOn Wed, Feb 23, 2011 at 01:43:08PM -0800, Junio C Hamano wrote:\n> While doing a final sanity check before merging a topic Bsomething, it is\n> a good idea to review what damage Bsomething branch would make, by running:\n> \n>     $ git diff ...Bsomething\n> \n> I however find myself often typing \"git diff ...B<TAB>\", seeing nothing\n> happening and then repeatedly hitting <TAB>, saying \"huh? <TAAAAAAAAB>!\".\n> \n> This change would hopefully help me, and others like me.\n\nI agree that this would be a good change ...\n\n> Even though there is no point in supporting \"git diff A..B\" (you can say\n> \"git diff A B\" just fine), but reusing complete-revlist was the easiest\n> and that form is supported as a benign but not so useful side effect.\n\n... and this side effect is nothing to worry about, ...\n\n> Signed-off-by: Junio C Hamano <gitster@pobox.com>\n> ---\n> \n>  * I sent this out a while ago and have been using it ever since, but\n>    totally forgot about it.  Likes, dislikes, alternatives?\n> \n>  contrib/completion/git-completion.bash |    2 +-\n>  1 files changed, 1 insertions(+), 1 deletions(-)\n> \n> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\n> index 64341d5..cf56514 100755\n> --- a/contrib/completion/git-completion.bash\n> +++ b/contrib/completion/git-completion.bash\n> @@ -1137,7 +1137,7 @@ _git_diff ()\n>  \t\treturn\n>  \t\t;;\n>  \tesac\n> -\t__git_complete_file\n> +\t__git_complete_revlist\n\n... but I don't think this is the right solution, because it\nintroduces a regression.\n\nThere is this 'ref:file' notation (as in 'git show master:README', but\nI don't know the proper term for it), which is understood by\n__git_complete_file(), and can be useful for 'git diff', e.g. to\ncompare a file in two branches when the file was renamed in between:\n\n  git diff branchA:old branchB:new\n\nHowever, __git_complete_revlist() doesn't understand this notation,\nand does plain filename completion after the ':', i.e. it lists all\nfiles and dirs in the current worktree including untracked files, not\njust the files that are actually present in the given ref, breaking\nthe completion for 'git diff branchA:o<TAB>'.\n\nHow about teaching __git_complete_file() to offer refs after '...'\ninstead?  It wouldn't make sense for any other commands for which we\nuse __git_complete_file() in the completion script, but the users\nwouldn't write '...' for those commands anyway, so this is in the same\n\"benign but not so useful side effect\" category.  But for 'git diff'\nit would allow the completion of both 'git diff ...B<TAB>' and 'git\ndiff branch:o<TAB>'.\n\nI mean something like this, but didn't test it that much.  The first\nhunk is just a sanity check to prevent invoking 'git ls-tree' in case\nthe user does 'git diff ...branch:o<TAB>', because it would trigger\nsome error messages by 'git ls-tree', and would later cause an error\nin 'git diff' anyway.\n\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 893b771..2b02505 100755\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -667,6 +667,9 @@ __git_complete_file ()\n \tlocal pfx ls ref cur\n \t_get_comp_words_by_ref -n =: cur\n \tcase \"$cur\" in\n+\t*...?*:*)\n+\t\treturn\n+\t\t;;\n \t?*:*)\n \t\tref=\"${cur%%:*}\"\n \t\tcur=\"${cur#*:}\"\n@@ -705,6 +708,11 @@ __git_complete_file ()\n \t\t\t\t       s/^.*\t//')\" \\\n \t\t\t-- \"$cur\"))\n \t\t;;\n+\t*...*)\n+\t\tpfx=\"${cur%...*}...\"\n+\t\tcur=\"${cur#*...}\"\n+\t\t__gitcomp \"$(__git_refs)\" \"$pfx\" \"$cur\"\n+\t\t;;\n \t*)\n \t\t__gitcomp \"$(__git_refs)\"\n \t\t;;\n"},{"id":"162169","messageId":"7vfwrd2wbn.fsf@alter.siamese.dyndns.org","threadId":"26585","inReplyTo":"20110224151328.GB14720@neumann","subject":"Re: [PATCH] completion: complete \"git diff ...branc<TAB>\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-02-24T17:09:48Z","receivedAt":"2011-02-24T17:09:48Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"SZEDER Gábor <szeder@ira.uka.de> writes:\n\n> There is this 'ref:file' notation (as in 'git show master:README', but\n> I don't know the proper term for it), which is understood by\n> __git_complete_file(), and can be useful for 'git diff', e.g. to\n> compare a file in two branches when the file was renamed in between:\n>\n>   git diff branchA:old branchB:new\n>\n> However, __git_complete_revlist() doesn't understand this notation,\n\nIf that is the case, I wonder if complete-revlist should learn it as well.\nThe \"<tree>:<path>\" notation is just one of the \"extended SHA-1\nexpressions\" to name an entry in a tree object and should be usable\nanywhere an object name is expected to occur.\n\nThe users of complete-revlist seems to be \"log\" and their friends, and\nthey don't expect arbitrary object names; they are only interested in\ncommit objects and tags and then paths.  Teaching <tree>:<path> to it may\nmake \"git log HEAD:bar<TAB>\" to complete to \"git log HEAD:bar/boz\" that\nwould be a nonsense, but anything that the original \"git log HEAD:bar\"\nwould complete would be a nonsense to begin with (as soon as you said\n\"HEAD:<something to follow>\", you are naming either a blob or a tree\nobject, and you cannot start log from them), so I don't see a harm done in\ndoing so.\n\nIOW, shouldn't there be just one unified complete-rev-then-path that is a\nsuperset of the current complete-revlist and complete-file that all the\ncurrent users of complete-revlist and complete-file should use?\n"},{"id":"163161","messageId":"1299780749-12435-1-git-send-email-szeder@ira.uka.de","threadId":"26585","inReplyTo":"7vfwrd2wbn.fsf@alter.siamese.dyndns.org","subject":"[PATCH 1/2] bash: fix misindented esac statement in __git_complete_file()","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2011-03-10T18:12:28Z","receivedAt":"2011-03-10T18:12:28Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>\n---\n contrib/completion/git-completion.bash |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 893b771..344a47f 100755\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -680,7 +680,7 @@ __git_complete_file ()\n \t\t*)\n \t\t\tls=\"$ref\"\n \t\t\t;;\n-\t    esac\n+\t\tesac\n \n \t\tcase \"$COMP_WORDBREAKS\" in\n \t\t*:*) : great ;;\n-- \n1.7.4.1.237.g62e25\n"},{"id":"163160","messageId":"1299780749-12435-2-git-send-email-szeder@ira.uka.de","threadId":"26585","inReplyTo":"1299780749-12435-1-git-send-email-szeder@ira.uka.de","subject":"[PATCH 2/2] bash: complete 'git diff ...branc<TAB>'","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2011-03-10T18:12:29Z","receivedAt":"2011-03-10T18:12:29Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"While doing a final sanity check before merging a topic Bsomething, it\nis a good idea to review what damage Bsomething branch would make, by\nrunning:\n\n    $ git diff ...Bsomething\n\nUnfortunately, our completion script for 'git diff' doesn't offer\nanything after '...'.  This is because 'git diff's completion function\ninvokes __git_complete_file() for non-option arguments to complete the\n'<tree>:<path>' extended SHA-1 notation, but this helper function\ndoesn't support refs after '...' or '..'.  Completion of refs after\n'...' or '..' is supported by the __git_complete_revlist() helper\nfunction, but that doesn't support '<tree>:<path>'.\n\nTo support both '...<ref>' and '<tree>:<path>' notations for 'git\ndiff', this patch, instead of adding yet another helper function,\njoins __git_complete_file() and __git_complete_revlist() into the new\ncommon function __git_complete_revlist_file().  The old helper\nfunctions __git_complete_file() and __git_complete_revlist() are\nchanged to be a direct wrapper around the new\n__git_complete_revlist_file(), because they might be used in\nuser-supplied completion scripts and we don't want to break them.\n\nThis change will cause some wrong suggestions for other commands which\nuse __git_complete_file() ('git diff' and friends) or\n__git_complete_revlist() ('git log' and friends), e.g. 'git diff\n...master:Doc<TAB>' and 'git log master:Doc<TAB>' will complete the\npath to 'Documentation/', although neither commands make any sense.\nHowever, both of these were actively wrong to begin with as soon as\nthe user entered the ':', so there is no real harm done.\n\nSuggested-by: Junio C Hamano <gitster@pobox.com>\nSigned-off-by: SZEDER Gábor <szeder@ira.uka.de>\n---\n contrib/completion/git-completion.bash |   29 ++++++++++++++++-------------\n 1 files changed, 16 insertions(+), 13 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 344a47f..0c48f1a 100755\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -662,11 +662,14 @@ __git_compute_merge_strategies ()\n \t: ${__git_merge_strategies:=$(__git_list_merge_strategies)}\n }\n \n-__git_complete_file ()\n+__git_complete_revlist_file ()\n {\n \tlocal pfx ls ref cur\n \t_get_comp_words_by_ref -n =: cur\n \tcase \"$cur\" in\n+\t*..?*:*)\n+\t\treturn\n+\t\t;;\n \t?*:*)\n \t\tref=\"${cur%%:*}\"\n \t\tcur=\"${cur#*:}\"\n@@ -705,17 +708,6 @@ __git_complete_file ()\n \t\t\t\t       s/^.*\t//')\" \\\n \t\t\t-- \"$cur\"))\n \t\t;;\n-\t*)\n-\t\t__gitcomp \"$(__git_refs)\"\n-\t\t;;\n-\tesac\n-}\n-\n-__git_complete_revlist ()\n-{\n-\tlocal pfx cur\n-\t_get_comp_words_by_ref -n =: cur\n-\tcase \"$cur\" in\n \t*...*)\n \t\tpfx=\"${cur%...*}...\"\n \t\tcur=\"${cur#*...}\"\n@@ -732,6 +724,17 @@ __git_complete_revlist ()\n \tesac\n }\n \n+\n+__git_complete_file ()\n+{\n+\t__git_complete_revlist_file\n+}\n+\n+__git_complete_revlist ()\n+{\n+\t__git_complete_revlist_file\n+}\n+\n __git_complete_remote_or_refspec ()\n {\n \tlocal cur words cword\n@@ -1354,7 +1357,7 @@ _git_diff ()\n \t\treturn\n \t\t;;\n \tesac\n-\t__git_complete_file\n+\t__git_complete_revlist_file\n }\n \n __git_mergetools_common=\"diffuse ecmerge emerge kdiff3 meld opendiff\n-- \n1.7.4.1.237.g62e25\n"},{"id":"163169","messageId":"7vhbba4vtk.fsf@alter.siamese.dyndns.org","threadId":"26585","inReplyTo":"1299780749-12435-2-git-send-email-szeder@ira.uka.de","subject":"Re: [PATCH 2/2] bash: complete 'git diff ...branc<TAB>'","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-03-10T19:30:47Z","receivedAt":"2011-03-10T19:30:47Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thanks.\n"}]}