{"thread":{"id":"43313","subject":"Re: [PATCH 12/10] Teach bash about git-repo-config.","startedAt":"2006-11-27T09:44:47Z","lastAt":"2006-11-28T07:53:25Z","messageCount":3,"participants":["Junio C Hamano","Shawn O. Pearce","Shawn Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":10},"messages":[{"id":"294387","messageId":"20061127094447.GA19273@spearce.org","threadId":"43313","inReplyTo":null,"subject":"[PATCH 12/10] Teach bash about git-repo-config.","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-11-27T09:44:47Z","receivedAt":"2006-11-27T09:44:47Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"This is a really ugly completion script for git-repo-config, but it has\nsome nice properties.  I've added all of the documented configuration\nparameters from Documentation/config.txt to the script, allowing the\nuser to complete any standard configuration parameter name.\n\nWe also have some intelligence for the remote.*.* and branch.*.* keys\nby completing not only the key name (e.g. remote.origin) but also the\nvalues (e.g. remote.*.fetch completes to the branches available on the\ncorresponding remote).\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n Yes, that's it.  I'm finally done tinkering with bash\n completion support for this week.  Total of 12 patches.\n Sorry about the numbering Junio; when I sent the first 10\n I thought I was going to bed, but then decided to stay\n up and hack a bit more...\n\n I know Linus would like to see the space thing corrected.\n I'll try to look at it next week if nobody beats me to it.\n\n contrib/completion/git-completion.bash |  154 ++++++++++++++++++++++++++++++++\n 1 files changed, 154 insertions(+), 0 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 47b393d..a957165 100755\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -43,6 +43,27 @@ __git_ps1 ()\n \tfi\n }\n \n+__git_heads ()\n+{\n+\tlocal cmd i is_hash=y dir=\"${1:-$(__gitdir)}\"\n+\tif [ -d \"$dir\" ]; then\n+\t\tfor i in $(git --git-dir=\"$dir\" \\\n+\t\t\tfor-each-ref --format='%(refname)' \\\n+\t\t\trefs/heads ); do\n+\t\t\techo \"${i#refs/heads/}\"\n+\t\tdone\n+\t\treturn\n+\tfi\n+\tfor i in $(git-ls-remote \"$dir\" 2>/dev/null); do\n+\t\tcase \"$is_hash,$i\" in\n+\t\ty,*) is_hash=n ;;\n+\t\tn,*^{}) is_hash=y ;;\n+\t\tn,refs/heads/*) is_hash=y; echo \"${i#refs/heads/}\" ;;\n+\t\tn,*) is_hash=y; echo \"$i\" ;;\n+\t\tesac\n+\tdone\n+}\n+\n __git_refs ()\n {\n \tlocal cmd i is_hash=y dir=\"${1:-$(__gitdir)}\"\n@@ -91,6 +112,23 @@ __git_refs2 ()\n \tdone\n }\n \n+__git_refs_remotes ()\n+{\n+\tlocal cmd i is_hash=y\n+\tfor i in $(git-ls-remote \"$1\" 2>/dev/null); do\n+\t\tcase \"$is_hash,$i\" in\n+\t\tn,refs/heads/*)\n+\t\t\tis_hash=y\n+\t\t\techo \"$i:refs/remotes/$1/${i#refs/heads/}\"\n+\t\t\t;;\n+\t\ty,*) is_hash=n ;;\n+\t\tn,*^{}) is_hash=y ;;\n+\t\tn,refs/tags/*) is_hash=y;;\n+\t\tn,*) is_hash=y; ;;\n+\t\tesac\n+\tdone\n+}\n+\n __git_remotes ()\n {\n \tlocal i ngoff IFS=$'\\n' d=\"$(__gitdir)\"\n@@ -520,6 +558,119 @@ _git_rebase ()\n \tCOMPREPLY=($(compgen -W \"$(__git_refs)\" -- \"$cur\"))\n }\n \n+_git_repo_config ()\n+{\n+\tlocal cur=\"${COMP_WORDS[COMP_CWORD]}\"\n+\tlocal prv=\"${COMP_WORDS[COMP_CWORD-1]}\"\n+\tcase \"$prv\" in\n+\tbranch.*.remote)\n+\t\tCOMPREPLY=($(compgen -W \"$(__git_remotes)\" -- \"$cur\"))\n+\t\treturn\n+\t\t;;\n+\tbranch.*.merge)\n+\t\tCOMPREPLY=($(compgen -W \"$(__git_refs)\" -- \"$cur\"))\n+\t\treturn\n+\t\t;;\n+\tremote.*.fetch)\n+\t\tlocal remote=\"${prv#remote.}\"\n+\t\tremote=\"${remote%.fetch}\"\n+\t\tCOMPREPLY=($(compgen -W \"$(__git_refs_remotes \"$remote\")\" \\\n+\t\t\t-- \"$cur\"))\n+\t\treturn\n+\t\t;;\n+\tremote.*.push)\n+\t\tlocal remote=\"${prv#remote.}\"\n+\t\tremote=\"${remote%.push}\"\n+\t\tCOMPREPLY=($(compgen -W \"$(git --git-dir=\"$(__gitdir)\" \\\n+\t\t\tfor-each-ref --format='%(refname):%(refname)' \\\n+\t\t\trefs/heads)\" -- \"$cur\"))\n+\t\treturn\n+\t\t;;\n+\t*.*)\n+\t\tCOMPREPLY=()\n+\t\treturn\n+\t\t;;\n+\tesac\n+\tcase \"$cur\" in\n+\t--*)\n+\t\tCOMPREPLY=($(compgen -W \"\n+\t\t\t--global --list --replace-all\n+\t\t\t--get --get-all --get-regexp\n+\t\t\t--unset --unset-all\n+\t\t\t\" -- \"$cur\"))\n+\t\treturn\n+\t\t;;\n+\tbranch.*.*)\n+\t\tlocal pfx=\"${cur%.*}.\"\n+\t\tcur=\"${cur##*.}\"\n+\t\tCOMPREPLY=($(compgen -P \"$pfx\" -W \"remote merge\" -- \"$cur\"))\n+\t\treturn\n+\t\t;;\n+\tbranch.*)\n+\t\tlocal pfx=\"${cur%.*}.\"\n+\t\tcur=\"${cur#*.}\"\n+\t\tCOMPREPLY=($(compgen -P \"$pfx\" -S . \\\n+\t\t\t-W \"$(__git_heads)\" -- \"$cur\"))\n+\t\treturn\n+\t\t;;\n+\tremote.*.*)\n+\t\tlocal pfx=\"${cur%.*}.\"\n+\t\tcur=\"${cur##*.}\"\n+\t\tCOMPREPLY=($(compgen -P \"$pfx\" -W \"url fetch push\" -- \"$cur\"))\n+\t\treturn\n+\t\t;;\n+\tremote.*)\n+\t\tlocal pfx=\"${cur%.*}.\"\n+\t\tcur=\"${cur#*.}\"\n+\t\tCOMPREPLY=($(compgen -P \"$pfx\" -S . \\\n+\t\t\t-W \"$(__git_remotes)\" -- \"$cur\"))\n+\t\treturn\n+\t\t;;\n+\tesac\n+\tCOMPREPLY=($(compgen -W \"\n+\t\tapply.whitespace\n+\t\tcore.fileMode\n+\t\tcore.gitProxy\n+\t\tcore.ignoreStat\n+\t\tcore.preferSymlinkRefs\n+\t\tcore.logAllRefUpdates\n+\t\tcore.repositoryFormatVersion\n+\t\tcore.sharedRepository\n+\t\tcore.warnAmbiguousRefs\n+\t\tcore.compression\n+\t\tcore.legacyHeaders\n+\t\ti18n.commitEncoding\n+\t\tdiff.color\n+\t\tdiff.renameLimit\n+\t\tdiff.renames\n+\t\tpager.color\n+\t\tstatus.color\n+\t\tlog.showroot\n+\t\tshow.difftree\n+\t\tshowbranch.default\n+\t\twhatchanged.difftree\n+\t\thttp.sslVerify\n+\t\thttp.sslCert\n+\t\thttp.sslKey\n+\t\thttp.sslCAInfo\n+\t\thttp.sslCAPath\n+\t\thttp.maxRequests\n+\t\thttp.lowSpeedLimit http.lowSpeedTime\n+\t\thttp.noEPSV\n+\t\tpack.window\n+\t\trepack.useDeltaBaseOffset\n+\t\tpull.octopus pull.twohead\n+\t\tmerge.summary\n+\t\treceive.unpackLimit\n+\t\treceive.denyNonFastForwards\n+\t\tuser.name user.email\n+\t\ttar.umask\n+\t\tgitcvs.enabled\n+\t\tgitcvs.logfile\n+\t\tbranch. remote.\n+\t\" -- \"$cur\"))\n+}\n+\n _git_reset ()\n {\n \tlocal cur=\"${COMP_WORDS[COMP_CWORD]}\"\n@@ -572,6 +723,7 @@ _git ()\n \tpull)        _git_pull ;;\n \tpush)        _git_push ;;\n \trebase)      _git_rebase ;;\n+\trepo-config) _git_repo_config ;;\n \treset)       _git_reset ;;\n \tshow)        _git_log ;;\n \tshow-branch) _git_log ;;\n@@ -605,6 +757,7 @@ complete -o default            -F _git_name_rev git-name-rev\n complete -o default -o nospace -F _git_pull git-pull\n complete -o default -o nospace -F _git_push git-push\n complete -o default            -F _git_rebase git-rebase\n+complete -o default            -F _git_repo_config git-repo-config\n complete -o default            -F _git_reset git-reset\n complete -o default            -F _git_log git-show\n complete -o default -o nospace -F _git_log git-show-branch\n@@ -626,6 +779,7 @@ complete -o default -o nospace -F _git_ls_tree git-ls-tree.exe\n complete -o default            -F _git_merge_base git-merge-base.exe\n complete -o default            -F _git_name_rev git-name-rev.exe\n complete -o default -o nospace -F _git_push git-push.exe\n+complete -o default            -F _git_repo_config git-repo-config\n complete -o default -o nospace -F _git_log git-show.exe\n complete -o default -o nospace -F _git_log git-show-branch.exe\n complete -o default -o nospace -F _git_log git-whatchanged.exe\n-- \n"},{"id":"294323","messageId":"7vodqscqty.fsf@assigned-by-dhcp.cox.net","threadId":"43313","inReplyTo":"20061127094447.GA19273@spearce.org","subject":"Re: [PATCH 12/10] Teach bash about git-repo-config.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-11-28T01:17:29Z","receivedAt":"2006-11-28T01:17:29Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Shawn O. Pearce\" <spearce@spearce.org> writes:\n\n>  Yes, that's it.  I'm finally done tinkering with bash\n>  completion support for this week.  Total of 12 patches.\n\nThanks.  I saw a funky behaviour when I tried this:\n\n\t$ git pull . ap<TAB>\n\n==>\n\t$ git pull . apfatal: Not a git repository: '.'\n\n"},{"id":"294707","messageId":"20061128075325.GB9056@spearce.org","threadId":"43313","inReplyTo":"7vodqscqty.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH 12/10] Teach bash about git-repo-config.","fromName":"Shawn Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-11-28T07:53:25Z","receivedAt":"2006-11-28T07:53:25Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Junio C Hamano <junkio@cox.net> wrote:\n> \"Shawn O. Pearce\" <spearce@spearce.org> writes:\n> \n> >  Yes, that's it.  I'm finally done tinkering with bash\n> >  completion support for this week.  Total of 12 patches.\n> \n> Thanks.  I saw a funky behaviour when I tried this:\n> \n> \t$ git pull . ap<TAB>\n> \n> ==>\n> \t$ git pull . apfatal: Not a git repository: '.'\n\nDoh.  Its the commit titled \"Support bash completion of refs/remote\".\nThe problem is I'm invoking git-for-each-ref wrong:\n\n\tgit --git-dir=. for-each-ref ...\n\nClearly \".\" isn't a git directory.  But ./.git is.  The breakage is\nthe switch from git-peek-remote to git-for-each-ref.  git-peek-remote\nnicely realized that \".\" wasn't a git directory but \"./.git\" was\nand went into ./.git to get the refs.  I switched to for-each-ref\nto get a potential speed boost (no need to dereference tags) but\nbroke the damn thing in the process.\n\nI thought I had tested this for-each-ref change out.  Apparently I\nmissed a case.\n\nI'll fix it tomorrow.\n\n-- \n"}]}