{"thread":{"id":"30595","subject":"[PATCH 0/2] completion: split into git-prompt.sh","startedAt":"2012-05-22T20:46:38Z","lastAt":"2012-11-08T13:19:10Z","messageCount":34,"participants":["Felipe Contreras","Zbigniew Jędrzejewski-Szmek","Ted Pavlic","Junio C Hamano","SZEDER Gábor","Thomas Rast","Ville Skyttä","Jonathan Nieder","Drew Northup","Danny Yates","Anders Kaseorg","Todd Zullinger"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"191946","messageId":"1337719600-7361-1-git-send-email-felipe.contreras@gmail.com","threadId":"30595","inReplyTo":null,"subject":"[PATCH 0/2] completion: split into git-prompt.sh","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2012-05-22T20:46:38Z","receivedAt":"2012-05-22T20:46:38Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Hi,\n\nThis has been discussed before, but nobody has actually done it. Details in the\nrelevant patch.\n\nFelipe Contreras (2):\n  completion: remove executable mode\n  completion: split __git_ps1 into a separate script\n\n contrib/completion/git-completion.bash |  257 +---------------------------\n contrib/completion/git-prompt.sh       |  287 ++++++++++++++++++++++++++++++++\n t/t9903-bash-prompt.sh                 |    2 +-\n 3 files changed, 290 insertions(+), 256 deletions(-)\n mode change 100755 => 100644 contrib/completion/git-completion.bash\n create mode 100644 contrib/completion/git-prompt.sh\n\n-- \n1.7.10.2\n"},{"id":"191947","messageId":"1337719600-7361-2-git-send-email-felipe.contreras@gmail.com","threadId":"30595","inReplyTo":"1337719600-7361-1-git-send-email-felipe.contreras@gmail.com","subject":"[PATCH 1/2] completion: remove executable mode","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2012-05-22T20:46:39Z","receivedAt":"2012-05-22T20:46:39Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"No reason to have it executable. Every way this script is intended to be\nused includes the 'source' command.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n 0 files changed\n mode change 100755 => 100644 contrib/completion/git-completion.bash\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nold mode 100755\nnew mode 100644\n-- \n1.7.10.2\n"},{"id":"191948","messageId":"1337719600-7361-3-git-send-email-felipe.contreras@gmail.com","threadId":"30595","inReplyTo":"1337719600-7361-1-git-send-email-felipe.contreras@gmail.com","subject":"[PATCH 2/2] completion: split __git_ps1 into a separate script","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2012-05-22T20:46:40Z","receivedAt":"2012-05-22T20:46:40Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"bash-completion 1.90 shipped with support to load completions\ndynamically[1], which means the git completion script wouldn't be loaded\nuntil the user types 'git <tab>'--this creates a problem to people using\n__git_ps1(); that function won't be available when the shell is first\ncreated.\n\nFor now distributions have workarounded this issue by moving the git\ncompletion to the \"compatdir\"[2]; this of course is not ideal.\n\nThe solution, proposed by Kerrick Staley[3], is to split the git script\nin two; the part that deals with __git_ps1() in one (i.e.\ngit-prompt.sh), and everything else in another (i.e.\ngit-completion.bash).\n\nAnother benefit of this is that zsh user that are not interested in the\nbash completion can use it for their prompts, which has been tried\nbefore[4].\n\nThe only slight issue is that __gitdir() would be duplicated, but this\nis probably not a big deal.\n\nSo let's go ahead and move __git_ps1() to a new file.\n\nWhile at this, I took the liberty to reformat the help text in the new\nfile.\n\n [1] http://anonscm.debian.org/gitweb/?p=bash-completion/bash-completion.git;a=commitdiff;h=99c4f7f25f50a7cb2fce86055bddfe389effa559\n [2] http://projects.archlinux.org/svntogit/packages.git/commit/trunk?h=packages/git&id=974380fabb8f9f412990b17063bf578d98c44a82\n [3] http://mid.gmane.org/CANaWP3w9KDu57aHquRRYt8td_haSWTBKs7zUHy-xu0B61gmr9A@mail.gmail.com\n [4] http://mid.gmane.org/1303824288-15591-1-git-send-email-mstormo@gmail.com\n\nCc: Kerrick Staley <mail@kerrickstaley.com>\nCc: Marius Storm-Olsen <mstormo@gmail.com>\nCc: Ville Skyttä <ville.skytta@iki.fi>\nCc: Dan McGee <dan@archlinux.org>\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.bash |  257 +---------------------------\n contrib/completion/git-prompt.sh       |  287 ++++++++++++++++++++++++++++++++\n t/t9903-bash-prompt.sh                 |    2 +-\n 3 files changed, 290 insertions(+), 256 deletions(-)\n create mode 100644 contrib/completion/git-prompt.sh\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 44af124..59e4b5f 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -20,46 +20,8 @@\n #    1) Copy this file to somewhere (e.g. ~/.git-completion.sh).\n #    2) Add the following line to your .bashrc/.zshrc:\n #        source ~/.git-completion.sh\n-#\n-#    3) Consider changing your PS1 to also show the current branch:\n-#         Bash: PS1='[\\u@\\h \\W$(__git_ps1 \" (%s)\")]\\$ '\n-#         ZSH:  PS1='[%n@%m %c$(__git_ps1 \" (%s)\")]\\$ '\n-#\n-#       The argument to __git_ps1 will be displayed only if you\n-#       are currently in a git repository.  The %s token will be\n-#       the name of the current branch.\n-#\n-#       In addition, if you set GIT_PS1_SHOWDIRTYSTATE to a nonempty\n-#       value, unstaged (*) and staged (+) changes will be shown next\n-#       to the branch name.  You can configure this per-repository\n-#       with the bash.showDirtyState variable, which defaults to true\n-#       once GIT_PS1_SHOWDIRTYSTATE is enabled.\n-#\n-#       You can also see if currently something is stashed, by setting\n-#       GIT_PS1_SHOWSTASHSTATE to a nonempty value. If something is stashed,\n-#       then a '$' will be shown next to the branch name.\n-#\n-#       If you would like to see if there're untracked files, then you can\n-#       set GIT_PS1_SHOWUNTRACKEDFILES to a nonempty value. If there're\n-#       untracked files, then a '%' will be shown next to the branch name.\n-#\n-#       If you would like to see the difference between HEAD and its\n-#       upstream, set GIT_PS1_SHOWUPSTREAM=\"auto\".  A \"<\" indicates\n-#       you are behind, \">\" indicates you are ahead, and \"<>\"\n-#       indicates you have diverged.  You can further control\n-#       behaviour by setting GIT_PS1_SHOWUPSTREAM to a space-separated\n-#       list of values:\n-#           verbose       show number of commits ahead/behind (+/-) upstream\n-#           legacy        don't use the '--count' option available in recent\n-#                         versions of git-rev-list\n-#           git           always compare HEAD to @{upstream}\n-#           svn           always compare HEAD to your SVN upstream\n-#       By default, __git_ps1 will compare HEAD to your SVN upstream\n-#       if it can find one, or @{upstream} otherwise.  Once you have\n-#       set GIT_PS1_SHOWUPSTREAM, you can override it on a\n-#       per-repository basis by setting the bash.showUpstream config\n-#       variable.\n-#\n+#    3) Consider changing your PS1 to also show the current branch,\n+#       see git-prompt.sh for details.\n \n if [[ -n ${ZSH_VERSION-} ]]; then\n \tautoload -U +X bashcompinit && bashcompinit\n@@ -92,221 +54,6 @@ __gitdir ()\n \tfi\n }\n \n-# stores the divergence from upstream in $p\n-# used by GIT_PS1_SHOWUPSTREAM\n-__git_ps1_show_upstream ()\n-{\n-\tlocal key value\n-\tlocal svn_remote svn_url_pattern count n\n-\tlocal upstream=git legacy=\"\" verbose=\"\"\n-\n-\tsvn_remote=()\n-\t# get some config options from git-config\n-\tlocal output=\"$(git config -z --get-regexp '^(svn-remote\\..*\\.url|bash\\.showupstream)$' 2>/dev/null | tr '\\0\\n' '\\n ')\"\n-\twhile read -r key value; do\n-\t\tcase \"$key\" in\n-\t\tbash.showupstream)\n-\t\t\tGIT_PS1_SHOWUPSTREAM=\"$value\"\n-\t\t\tif [[ -z \"${GIT_PS1_SHOWUPSTREAM}\" ]]; then\n-\t\t\t\tp=\"\"\n-\t\t\t\treturn\n-\t\t\tfi\n-\t\t\t;;\n-\t\tsvn-remote.*.url)\n-\t\t\tsvn_remote[ $((${#svn_remote[@]} + 1)) ]=\"$value\"\n-\t\t\tsvn_url_pattern+=\"\\\\|$value\"\n-\t\t\tupstream=svn+git # default upstream is SVN if available, else git\n-\t\t\t;;\n-\t\tesac\n-\tdone <<< \"$output\"\n-\n-\t# parse configuration values\n-\tfor option in ${GIT_PS1_SHOWUPSTREAM}; do\n-\t\tcase \"$option\" in\n-\t\tgit|svn) upstream=\"$option\" ;;\n-\t\tverbose) verbose=1 ;;\n-\t\tlegacy)  legacy=1  ;;\n-\t\tesac\n-\tdone\n-\n-\t# Find our upstream\n-\tcase \"$upstream\" in\n-\tgit)    upstream=\"@{upstream}\" ;;\n-\tsvn*)\n-\t\t# get the upstream from the \"git-svn-id: ...\" in a commit message\n-\t\t# (git-svn uses essentially the same procedure internally)\n-\t\tlocal svn_upstream=($(git log --first-parent -1 \\\n-\t\t\t\t\t--grep=\"^git-svn-id: \\(${svn_url_pattern#??}\\)\" 2>/dev/null))\n-\t\tif [[ 0 -ne ${#svn_upstream[@]} ]]; then\n-\t\t\tsvn_upstream=${svn_upstream[ ${#svn_upstream[@]} - 2 ]}\n-\t\t\tsvn_upstream=${svn_upstream%@*}\n-\t\t\tlocal n_stop=\"${#svn_remote[@]}\"\n-\t\t\tfor ((n=1; n <= n_stop; n++)); do\n-\t\t\t\tsvn_upstream=${svn_upstream#${svn_remote[$n]}}\n-\t\t\tdone\n-\n-\t\t\tif [[ -z \"$svn_upstream\" ]]; then\n-\t\t\t\t# default branch name for checkouts with no layout:\n-\t\t\t\tupstream=${GIT_SVN_ID:-git-svn}\n-\t\t\telse\n-\t\t\t\tupstream=${svn_upstream#/}\n-\t\t\tfi\n-\t\telif [[ \"svn+git\" = \"$upstream\" ]]; then\n-\t\t\tupstream=\"@{upstream}\"\n-\t\tfi\n-\t\t;;\n-\tesac\n-\n-\t# Find how many commits we are ahead/behind our upstream\n-\tif [[ -z \"$legacy\" ]]; then\n-\t\tcount=\"$(git rev-list --count --left-right \\\n-\t\t\t\t\"$upstream\"...HEAD 2>/dev/null)\"\n-\telse\n-\t\t# produce equivalent output to --count for older versions of git\n-\t\tlocal commits\n-\t\tif commits=\"$(git rev-list --left-right \"$upstream\"...HEAD 2>/dev/null)\"\n-\t\tthen\n-\t\t\tlocal commit behind=0 ahead=0\n-\t\t\tfor commit in $commits\n-\t\t\tdo\n-\t\t\t\tcase \"$commit\" in\n-\t\t\t\t\"<\"*) ((behind++)) ;;\n-\t\t\t\t*)    ((ahead++))  ;;\n-\t\t\t\tesac\n-\t\t\tdone\n-\t\t\tcount=\"$behind\t$ahead\"\n-\t\telse\n-\t\t\tcount=\"\"\n-\t\tfi\n-\tfi\n-\n-\t# calculate the result\n-\tif [[ -z \"$verbose\" ]]; then\n-\t\tcase \"$count\" in\n-\t\t\"\") # no upstream\n-\t\t\tp=\"\" ;;\n-\t\t\"0\t0\") # equal to upstream\n-\t\t\tp=\"=\" ;;\n-\t\t\"0\t\"*) # ahead of upstream\n-\t\t\tp=\">\" ;;\n-\t\t*\"\t0\") # behind upstream\n-\t\t\tp=\"<\" ;;\n-\t\t*)\t    # diverged from upstream\n-\t\t\tp=\"<>\" ;;\n-\t\tesac\n-\telse\n-\t\tcase \"$count\" in\n-\t\t\"\") # no upstream\n-\t\t\tp=\"\" ;;\n-\t\t\"0\t0\") # equal to upstream\n-\t\t\tp=\" u=\" ;;\n-\t\t\"0\t\"*) # ahead of upstream\n-\t\t\tp=\" u+${count#0\t}\" ;;\n-\t\t*\"\t0\") # behind upstream\n-\t\t\tp=\" u-${count%\t0}\" ;;\n-\t\t*)\t    # diverged from upstream\n-\t\t\tp=\" u+${count#*\t}-${count%\t*}\" ;;\n-\t\tesac\n-\tfi\n-\n-}\n-\n-\n-# __git_ps1 accepts 0 or 1 arguments (i.e., format string)\n-# returns text to add to bash PS1 prompt (includes branch name)\n-__git_ps1 ()\n-{\n-\tlocal g=\"$(__gitdir)\"\n-\tif [ -n \"$g\" ]; then\n-\t\tlocal r=\"\"\n-\t\tlocal b=\"\"\n-\t\tif [ -f \"$g/rebase-merge/interactive\" ]; then\n-\t\t\tr=\"|REBASE-i\"\n-\t\t\tb=\"$(cat \"$g/rebase-merge/head-name\")\"\n-\t\telif [ -d \"$g/rebase-merge\" ]; then\n-\t\t\tr=\"|REBASE-m\"\n-\t\t\tb=\"$(cat \"$g/rebase-merge/head-name\")\"\n-\t\telse\n-\t\t\tif [ -d \"$g/rebase-apply\" ]; then\n-\t\t\t\tif [ -f \"$g/rebase-apply/rebasing\" ]; then\n-\t\t\t\t\tr=\"|REBASE\"\n-\t\t\t\telif [ -f \"$g/rebase-apply/applying\" ]; then\n-\t\t\t\t\tr=\"|AM\"\n-\t\t\t\telse\n-\t\t\t\t\tr=\"|AM/REBASE\"\n-\t\t\t\tfi\n-\t\t\telif [ -f \"$g/MERGE_HEAD\" ]; then\n-\t\t\t\tr=\"|MERGING\"\n-\t\t\telif [ -f \"$g/CHERRY_PICK_HEAD\" ]; then\n-\t\t\t\tr=\"|CHERRY-PICKING\"\n-\t\t\telif [ -f \"$g/BISECT_LOG\" ]; then\n-\t\t\t\tr=\"|BISECTING\"\n-\t\t\tfi\n-\n-\t\t\tb=\"$(git symbolic-ref HEAD 2>/dev/null)\" || {\n-\n-\t\t\t\tb=\"$(\n-\t\t\t\tcase \"${GIT_PS1_DESCRIBE_STYLE-}\" in\n-\t\t\t\t(contains)\n-\t\t\t\t\tgit describe --contains HEAD ;;\n-\t\t\t\t(branch)\n-\t\t\t\t\tgit describe --contains --all HEAD ;;\n-\t\t\t\t(describe)\n-\t\t\t\t\tgit describe HEAD ;;\n-\t\t\t\t(* | default)\n-\t\t\t\t\tgit describe --tags --exact-match HEAD ;;\n-\t\t\t\tesac 2>/dev/null)\" ||\n-\n-\t\t\t\tb=\"$(cut -c1-7 \"$g/HEAD\" 2>/dev/null)...\" ||\n-\t\t\t\tb=\"unknown\"\n-\t\t\t\tb=\"($b)\"\n-\t\t\t}\n-\t\tfi\n-\n-\t\tlocal w=\"\"\n-\t\tlocal i=\"\"\n-\t\tlocal s=\"\"\n-\t\tlocal u=\"\"\n-\t\tlocal c=\"\"\n-\t\tlocal p=\"\"\n-\n-\t\tif [ \"true\" = \"$(git rev-parse --is-inside-git-dir 2>/dev/null)\" ]; then\n-\t\t\tif [ \"true\" = \"$(git rev-parse --is-bare-repository 2>/dev/null)\" ]; then\n-\t\t\t\tc=\"BARE:\"\n-\t\t\telse\n-\t\t\t\tb=\"GIT_DIR!\"\n-\t\t\tfi\n-\t\telif [ \"true\" = \"$(git rev-parse --is-inside-work-tree 2>/dev/null)\" ]; then\n-\t\t\tif [ -n \"${GIT_PS1_SHOWDIRTYSTATE-}\" ]; then\n-\t\t\t\tif [ \"$(git config --bool bash.showDirtyState)\" != \"false\" ]; then\n-\t\t\t\t\tgit diff --no-ext-diff --quiet --exit-code || w=\"*\"\n-\t\t\t\t\tif git rev-parse --quiet --verify HEAD >/dev/null; then\n-\t\t\t\t\t\tgit diff-index --cached --quiet HEAD -- || i=\"+\"\n-\t\t\t\t\telse\n-\t\t\t\t\t\ti=\"#\"\n-\t\t\t\t\tfi\n-\t\t\t\tfi\n-\t\t\tfi\n-\t\t\tif [ -n \"${GIT_PS1_SHOWSTASHSTATE-}\" ]; then\n-\t\t\t\tgit rev-parse --verify refs/stash >/dev/null 2>&1 && s=\"$\"\n-\t\t\tfi\n-\n-\t\t\tif [ -n \"${GIT_PS1_SHOWUNTRACKEDFILES-}\" ]; then\n-\t\t\t\tif [ -n \"$(git ls-files --others --exclude-standard)\" ]; then\n-\t\t\t\t\tu=\"%\"\n-\t\t\t\tfi\n-\t\t\tfi\n-\n-\t\t\tif [ -n \"${GIT_PS1_SHOWUPSTREAM-}\" ]; then\n-\t\t\t\t__git_ps1_show_upstream\n-\t\t\tfi\n-\t\tfi\n-\n-\t\tlocal f=\"$w$i$s$u\"\n-\t\tprintf -- \"${1:- (%s)}\" \"$c${b##refs/heads/}${f:+ $f}$r$p\"\n-\tfi\n-}\n-\n __gitcomp_1 ()\n {\n \tlocal c IFS=$' \\t\\n'\ndiff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\nnew file mode 100644\nindex 0000000..8e2e9f3\n--- /dev/null\n+++ b/contrib/completion/git-prompt.sh\n@@ -0,0 +1,287 @@\n+# bash/zsh git prompt support\n+#\n+# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>\n+# Distributed under the GNU General Public License, version 2.0.\n+#\n+# This script allows you to see the current branch in your prompt.\n+#\n+# To enable:\n+#\n+#    1) Copy this file to somewhere (e.g. ~/.git-prompt.sh).\n+#    2) Add the following line to your .bashrc/.zshrc:\n+#        source ~/.git-prompt.sh\n+#    3) Change your PS1 to also show the current branch:\n+#         Bash: PS1='[\\u@\\h \\W$(__git_ps1 \" (%s)\")]\\$ '\n+#         ZSH:  PS1='[%n@%m %c$(__git_ps1 \" (%s)\")]\\$ '\n+#\n+# The argument to __git_ps1 will be displayed only if you are currently\n+# in a git repository.  The %s token will be the name of the current\n+# branch.\n+#\n+# In addition, if you set GIT_PS1_SHOWDIRTYSTATE to a nonempty value,\n+# unstaged (*) and staged (+) changes will be shown next to the branch\n+# name.  You can configure this per-repository with the\n+# bash.showDirtyState variable, which defaults to true once\n+# GIT_PS1_SHOWDIRTYSTATE is enabled.\n+#\n+# You can also see if currently something is stashed, by setting\n+# GIT_PS1_SHOWSTASHSTATE to a nonempty value. If something is stashed,\n+# then a '$' will be shown next to the branch name.\n+#\n+# If you would like to see if there're untracked files, then you can set\n+# GIT_PS1_SHOWUNTRACKEDFILES to a nonempty value. If there're untracked\n+# files, then a '%' will be shown next to the branch name.\n+#\n+# If you would like to see the difference between HEAD and its upstream,\n+# set GIT_PS1_SHOWUPSTREAM=\"auto\".  A \"<\" indicates you are behind, \">\"\n+# indicates you are ahead, and \"<>\" indicates you have diverged.  You\n+# can further control behaviour by setting GIT_PS1_SHOWUPSTREAM to a\n+# space-separated list of values:\n+#\n+#     verbose       show number of commits ahead/behind (+/-) upstream\n+#     legacy        don't use the '--count' option available in recent\n+#                   versions of git-rev-list\n+#     git           always compare HEAD to @{upstream}\n+#     svn           always compare HEAD to your SVN upstream\n+#\n+# By default, __git_ps1 will compare HEAD to your SVN upstream if it can\n+# find one, or @{upstream} otherwise.  Once you have set\n+# GIT_PS1_SHOWUPSTREAM, you can override it on a per-repository basis by\n+# setting the bash.showUpstream config variable.\n+\n+# __gitdir accepts 0 or 1 arguments (i.e., location)\n+# returns location of .git repo\n+__gitdir ()\n+{\n+\tif [ -z \"${1-}\" ]; then\n+\t\tif [ -n \"${__git_dir-}\" ]; then\n+\t\t\techo \"$__git_dir\"\n+\t\telif [ -n \"${GIT_DIR-}\" ]; then\n+\t\t\ttest -d \"${GIT_DIR-}\" || return 1\n+\t\t\techo \"$GIT_DIR\"\n+\t\telif [ -d .git ]; then\n+\t\t\techo .git\n+\t\telse\n+\t\t\tgit rev-parse --git-dir 2>/dev/null\n+\t\tfi\n+\telif [ -d \"$1/.git\" ]; then\n+\t\techo \"$1/.git\"\n+\telse\n+\t\techo \"$1\"\n+\tfi\n+}\n+\n+# stores the divergence from upstream in $p\n+# used by GIT_PS1_SHOWUPSTREAM\n+__git_ps1_show_upstream ()\n+{\n+\tlocal key value\n+\tlocal svn_remote svn_url_pattern count n\n+\tlocal upstream=git legacy=\"\" verbose=\"\"\n+\n+\tsvn_remote=()\n+\t# get some config options from git-config\n+\tlocal output=\"$(git config -z --get-regexp '^(svn-remote\\..*\\.url|bash\\.showupstream)$' 2>/dev/null | tr '\\0\\n' '\\n ')\"\n+\twhile read -r key value; do\n+\t\tcase \"$key\" in\n+\t\tbash.showupstream)\n+\t\t\tGIT_PS1_SHOWUPSTREAM=\"$value\"\n+\t\t\tif [[ -z \"${GIT_PS1_SHOWUPSTREAM}\" ]]; then\n+\t\t\t\tp=\"\"\n+\t\t\t\treturn\n+\t\t\tfi\n+\t\t\t;;\n+\t\tsvn-remote.*.url)\n+\t\t\tsvn_remote[ $((${#svn_remote[@]} + 1)) ]=\"$value\"\n+\t\t\tsvn_url_pattern+=\"\\\\|$value\"\n+\t\t\tupstream=svn+git # default upstream is SVN if available, else git\n+\t\t\t;;\n+\t\tesac\n+\tdone <<< \"$output\"\n+\n+\t# parse configuration values\n+\tfor option in ${GIT_PS1_SHOWUPSTREAM}; do\n+\t\tcase \"$option\" in\n+\t\tgit|svn) upstream=\"$option\" ;;\n+\t\tverbose) verbose=1 ;;\n+\t\tlegacy)  legacy=1  ;;\n+\t\tesac\n+\tdone\n+\n+\t# Find our upstream\n+\tcase \"$upstream\" in\n+\tgit)    upstream=\"@{upstream}\" ;;\n+\tsvn*)\n+\t\t# get the upstream from the \"git-svn-id: ...\" in a commit message\n+\t\t# (git-svn uses essentially the same procedure internally)\n+\t\tlocal svn_upstream=($(git log --first-parent -1 \\\n+\t\t\t\t\t--grep=\"^git-svn-id: \\(${svn_url_pattern#??}\\)\" 2>/dev/null))\n+\t\tif [[ 0 -ne ${#svn_upstream[@]} ]]; then\n+\t\t\tsvn_upstream=${svn_upstream[ ${#svn_upstream[@]} - 2 ]}\n+\t\t\tsvn_upstream=${svn_upstream%@*}\n+\t\t\tlocal n_stop=\"${#svn_remote[@]}\"\n+\t\t\tfor ((n=1; n <= n_stop; n++)); do\n+\t\t\t\tsvn_upstream=${svn_upstream#${svn_remote[$n]}}\n+\t\t\tdone\n+\n+\t\t\tif [[ -z \"$svn_upstream\" ]]; then\n+\t\t\t\t# default branch name for checkouts with no layout:\n+\t\t\t\tupstream=${GIT_SVN_ID:-git-svn}\n+\t\t\telse\n+\t\t\t\tupstream=${svn_upstream#/}\n+\t\t\tfi\n+\t\telif [[ \"svn+git\" = \"$upstream\" ]]; then\n+\t\t\tupstream=\"@{upstream}\"\n+\t\tfi\n+\t\t;;\n+\tesac\n+\n+\t# Find how many commits we are ahead/behind our upstream\n+\tif [[ -z \"$legacy\" ]]; then\n+\t\tcount=\"$(git rev-list --count --left-right \\\n+\t\t\t\t\"$upstream\"...HEAD 2>/dev/null)\"\n+\telse\n+\t\t# produce equivalent output to --count for older versions of git\n+\t\tlocal commits\n+\t\tif commits=\"$(git rev-list --left-right \"$upstream\"...HEAD 2>/dev/null)\"\n+\t\tthen\n+\t\t\tlocal commit behind=0 ahead=0\n+\t\t\tfor commit in $commits\n+\t\t\tdo\n+\t\t\t\tcase \"$commit\" in\n+\t\t\t\t\"<\"*) ((behind++)) ;;\n+\t\t\t\t*)    ((ahead++))  ;;\n+\t\t\t\tesac\n+\t\t\tdone\n+\t\t\tcount=\"$behind\t$ahead\"\n+\t\telse\n+\t\t\tcount=\"\"\n+\t\tfi\n+\tfi\n+\n+\t# calculate the result\n+\tif [[ -z \"$verbose\" ]]; then\n+\t\tcase \"$count\" in\n+\t\t\"\") # no upstream\n+\t\t\tp=\"\" ;;\n+\t\t\"0\t0\") # equal to upstream\n+\t\t\tp=\"=\" ;;\n+\t\t\"0\t\"*) # ahead of upstream\n+\t\t\tp=\">\" ;;\n+\t\t*\"\t0\") # behind upstream\n+\t\t\tp=\"<\" ;;\n+\t\t*)\t    # diverged from upstream\n+\t\t\tp=\"<>\" ;;\n+\t\tesac\n+\telse\n+\t\tcase \"$count\" in\n+\t\t\"\") # no upstream\n+\t\t\tp=\"\" ;;\n+\t\t\"0\t0\") # equal to upstream\n+\t\t\tp=\" u=\" ;;\n+\t\t\"0\t\"*) # ahead of upstream\n+\t\t\tp=\" u+${count#0\t}\" ;;\n+\t\t*\"\t0\") # behind upstream\n+\t\t\tp=\" u-${count%\t0}\" ;;\n+\t\t*)\t    # diverged from upstream\n+\t\t\tp=\" u+${count#*\t}-${count%\t*}\" ;;\n+\t\tesac\n+\tfi\n+\n+}\n+\n+\n+# __git_ps1 accepts 0 or 1 arguments (i.e., format string)\n+# returns text to add to bash PS1 prompt (includes branch name)\n+__git_ps1 ()\n+{\n+\tlocal g=\"$(__gitdir)\"\n+\tif [ -n \"$g\" ]; then\n+\t\tlocal r=\"\"\n+\t\tlocal b=\"\"\n+\t\tif [ -f \"$g/rebase-merge/interactive\" ]; then\n+\t\t\tr=\"|REBASE-i\"\n+\t\t\tb=\"$(cat \"$g/rebase-merge/head-name\")\"\n+\t\telif [ -d \"$g/rebase-merge\" ]; then\n+\t\t\tr=\"|REBASE-m\"\n+\t\t\tb=\"$(cat \"$g/rebase-merge/head-name\")\"\n+\t\telse\n+\t\t\tif [ -d \"$g/rebase-apply\" ]; then\n+\t\t\t\tif [ -f \"$g/rebase-apply/rebasing\" ]; then\n+\t\t\t\t\tr=\"|REBASE\"\n+\t\t\t\telif [ -f \"$g/rebase-apply/applying\" ]; then\n+\t\t\t\t\tr=\"|AM\"\n+\t\t\t\telse\n+\t\t\t\t\tr=\"|AM/REBASE\"\n+\t\t\t\tfi\n+\t\t\telif [ -f \"$g/MERGE_HEAD\" ]; then\n+\t\t\t\tr=\"|MERGING\"\n+\t\t\telif [ -f \"$g/CHERRY_PICK_HEAD\" ]; then\n+\t\t\t\tr=\"|CHERRY-PICKING\"\n+\t\t\telif [ -f \"$g/BISECT_LOG\" ]; then\n+\t\t\t\tr=\"|BISECTING\"\n+\t\t\tfi\n+\n+\t\t\tb=\"$(git symbolic-ref HEAD 2>/dev/null)\" || {\n+\n+\t\t\t\tb=\"$(\n+\t\t\t\tcase \"${GIT_PS1_DESCRIBE_STYLE-}\" in\n+\t\t\t\t(contains)\n+\t\t\t\t\tgit describe --contains HEAD ;;\n+\t\t\t\t(branch)\n+\t\t\t\t\tgit describe --contains --all HEAD ;;\n+\t\t\t\t(describe)\n+\t\t\t\t\tgit describe HEAD ;;\n+\t\t\t\t(* | default)\n+\t\t\t\t\tgit describe --tags --exact-match HEAD ;;\n+\t\t\t\tesac 2>/dev/null)\" ||\n+\n+\t\t\t\tb=\"$(cut -c1-7 \"$g/HEAD\" 2>/dev/null)...\" ||\n+\t\t\t\tb=\"unknown\"\n+\t\t\t\tb=\"($b)\"\n+\t\t\t}\n+\t\tfi\n+\n+\t\tlocal w=\"\"\n+\t\tlocal i=\"\"\n+\t\tlocal s=\"\"\n+\t\tlocal u=\"\"\n+\t\tlocal c=\"\"\n+\t\tlocal p=\"\"\n+\n+\t\tif [ \"true\" = \"$(git rev-parse --is-inside-git-dir 2>/dev/null)\" ]; then\n+\t\t\tif [ \"true\" = \"$(git rev-parse --is-bare-repository 2>/dev/null)\" ]; then\n+\t\t\t\tc=\"BARE:\"\n+\t\t\telse\n+\t\t\t\tb=\"GIT_DIR!\"\n+\t\t\tfi\n+\t\telif [ \"true\" = \"$(git rev-parse --is-inside-work-tree 2>/dev/null)\" ]; then\n+\t\t\tif [ -n \"${GIT_PS1_SHOWDIRTYSTATE-}\" ]; then\n+\t\t\t\tif [ \"$(git config --bool bash.showDirtyState)\" != \"false\" ]; then\n+\t\t\t\t\tgit diff --no-ext-diff --quiet --exit-code || w=\"*\"\n+\t\t\t\t\tif git rev-parse --quiet --verify HEAD >/dev/null; then\n+\t\t\t\t\t\tgit diff-index --cached --quiet HEAD -- || i=\"+\"\n+\t\t\t\t\telse\n+\t\t\t\t\t\ti=\"#\"\n+\t\t\t\t\tfi\n+\t\t\t\tfi\n+\t\t\tfi\n+\t\t\tif [ -n \"${GIT_PS1_SHOWSTASHSTATE-}\" ]; then\n+\t\t\t\tgit rev-parse --verify refs/stash >/dev/null 2>&1 && s=\"$\"\n+\t\t\tfi\n+\n+\t\t\tif [ -n \"${GIT_PS1_SHOWUNTRACKEDFILES-}\" ]; then\n+\t\t\t\tif [ -n \"$(git ls-files --others --exclude-standard)\" ]; then\n+\t\t\t\t\tu=\"%\"\n+\t\t\t\tfi\n+\t\t\tfi\n+\n+\t\t\tif [ -n \"${GIT_PS1_SHOWUPSTREAM-}\" ]; then\n+\t\t\t\t__git_ps1_show_upstream\n+\t\t\tfi\n+\t\tfi\n+\n+\t\tlocal f=\"$w$i$s$u\"\n+\t\tprintf -- \"${1:- (%s)}\" \"$c${b##refs/heads/}${f:+ $f}$r$p\"\n+\tfi\n+}\ndiff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh\nindex 96468ce..f17c1f8 100755\n--- a/t/t9903-bash-prompt.sh\n+++ b/t/t9903-bash-prompt.sh\n@@ -7,7 +7,7 @@ test_description='test git-specific bash prompt functions'\n \n . ./lib-bash.sh\n \n-. \"$GIT_BUILD_DIR/contrib/completion/git-completion.bash\"\n+. \"$GIT_BUILD_DIR/contrib/completion/git-prompt.sh\"\n \n actual=\"$TRASH_DIRECTORY/actual\"\n \n-- \n1.7.10.2\n"},{"id":"191952","messageId":"4FBC0019.6030702@in.waw.pl","threadId":"30595","inReplyTo":"1337719600-7361-3-git-send-email-felipe.contreras@gmail.com","subject":"Re: [PATCH 2/2] completion: split __git_ps1 into a separate script","fromName":"Zbigniew Jędrzejewski-Szmek","fromEmail":"zbyszek@in.waw.pl","sentAt":"2012-05-22T21:07:37Z","receivedAt":"2012-05-22T21:07:37Z","isPatch":true,"sender":{"key":"zbyszek@in.waw.pl","avatar":"https://avatars.githubusercontent.com/u/349618?v=4"},"body":"On 05/22/2012 10:46 PM, Felipe Contreras wrote:\n>  contrib/completion/git-completion.bash |  257 +---------------------------\n>  contrib/completion/git-prompt.sh       |  287 ++++++++++++++++++++++++++++++++\n>  t/t9903-bash-prompt.sh                 |    2 +-\n>  3 files changed, 290 insertions(+), 256 deletions(-)\n>  create mode 100644 contrib/completion/git-prompt.sh\nHi,\nsince git-prompt is not completion related anymore, should a different\ndirectory be used?\n\nZbyszek\n"},{"id":"191958","messageId":"CAOnadRGgduprp_Dbjzf_TsyQQQjivzKxCgUq4y_HevvtKd7h7Q@mail.gmail.com","threadId":"30595","inReplyTo":"1337719600-7361-3-git-send-email-felipe.contreras@gmail.com","subject":"Re: [PATCH 2/2] completion: split __git_ps1 into a separate script","fromName":"Ted Pavlic","fromEmail":"ted@tedpavlic.com","sentAt":"2012-05-22T22:27:08Z","receivedAt":"2012-05-22T22:27:08Z","isPatch":true,"sender":{"key":"ted@tedpavlic.com","avatar":"https://gravatar.com/avatar/d085392370ff4c028cf17a0e81e0647744c9682fbcb36b499f31d08ef80ef569?d=mp&s=160"},"body":"> The solution, proposed by Kerrick Staley[3], is to split the git script\n> in two; the part that deals with __git_ps1() in one (i.e.\n> git-prompt.sh), and everything else in another (i.e.\n> git-completion.bash).\n\nSeems like this solution has popped up on lots of forums for about\nevery Linux distribution around the time the new bash completion was\nintroduced. I'm not sure Kerric Staley deserves sole attribution\n(sorry Kerrick; I mean no offense).\n\nMoreover, every time the subject of splitting __gitdir out comes up, a\nside discussion about all of the complications that could cause comes\nup... and people give up and hope that the folks upstream (i.e., here)\nwill come up with a better solution.\n\nIf it was so simple to just split __gitdir out, I think it would have\nalready been done.\n\n> The only slight issue is that __gitdir() would be duplicated, but this\n> is probably not a big deal.\n\nThat seems ugly. I know that splitting __gitdir out is also ugly, but\nI know that there are going to be a lot more people who use git\ncompletion than git_ps1. Consequently, in a duplicated __gitdir\nscneario, I worry that __gitdir will receive more attention and may\nrelatively quickly diverge in implementation if not very careful in\napproving patches. Moreover, a __gitdir of the future may not be\natomic and will pick up side effects and become impossible to manage\nin two places.\n\nSo maybe a split out \"git-gitdir.sh\" that both files include would be\n\"better.\" Either that or the functionality of \"__gitdir\" gets pulled\ninto git itself. (perhaps a git-gitdir added to the main git\ndistribution)\n\n> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n\nAs the patch is from you, there's no need to sign off on it too.\n\n--Ted\n\n-- \nTed Pavlic <ted@tedpavlic.com>\n"},{"id":"191959","messageId":"CAOnadRGBi0+Zno_eqzzkJjoUfXh=vEpEV5Cf_6zjOV42XPjXdg@mail.gmail.com","threadId":"30595","inReplyTo":"4FBC0019.6030702@in.waw.pl","subject":"Re: [PATCH 2/2] completion: split __git_ps1 into a separate script","fromName":"Ted Pavlic","fromEmail":"ted@tedpavlic.com","sentAt":"2012-05-22T22:29:45Z","receivedAt":"2012-05-22T22:29:45Z","isPatch":true,"sender":{"key":"ted@tedpavlic.com","avatar":"https://gravatar.com/avatar/d085392370ff4c028cf17a0e81e0647744c9682fbcb36b499f31d08ef80ef569?d=mp&s=160"},"body":">>  create mode 100644 contrib/completion/git-prompt.sh\n> Hi,\n> since git-prompt is not completion related anymore, should a different\n> directory be used?\n\nMaking it even more likely that the __gitdir in one will someday not\nmatch the __gitdir in another...\n\nMaybe __gitdir should live inside git-prompt and git-completion would\ninclude git-prompt. That would make everything backward compatible\ntoo. And that way there's a good answer to why git-prompt lives inside\nthe completion directory.\n\n-- \nTed Pavlic <ted@tedpavlic.com>\n"},{"id":"191975","messageId":"CAMP44s0jLdNo89+c7+fBSokdxhCvPRnRKfhgVKnziMmv0vySXw@mail.gmail.com","threadId":"30595","inReplyTo":"CAOnadRGgduprp_Dbjzf_TsyQQQjivzKxCgUq4y_HevvtKd7h7Q@mail.gmail.com","subject":"Re: [PATCH 2/2] completion: split __git_ps1 into a separate script","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2012-05-23T11:53:07Z","receivedAt":"2012-05-23T11:53:07Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Wed, May 23, 2012 at 12:27 AM, Ted Pavlic <ted@tedpavlic.com> wrote:\n>> The solution, proposed by Kerrick Staley[3], is to split the git script\n>> in two; the part that deals with __git_ps1() in one (i.e.\n>> git-prompt.sh), and everything else in another (i.e.\n>> git-completion.bash).\n>\n> Seems like this solution has popped up on lots of forums for about\n> every Linux distribution around the time the new bash completion was\n> introduced. I'm not sure Kerric Staley deserves sole attribution\n> (sorry Kerrick; I mean no offense).\n\nI didn't attribute it to him, I merely said he proposed it, which he\ndid, I did not make any statement about him being the sole author of\nthis idea.\n\nI don't recall this solution for this problem being proposed in this\nmailing list by anybody else though. And I don't think it's relevant.\n\n> Moreover, every time the subject of splitting __gitdir out comes up, a\n> side discussion about all of the complications that could cause comes\n> up... and people give up and hope that the folks upstream (i.e., here)\n> will come up with a better solution.\n\nThis is the reply Kerrick got to his suggestion from Jeff King:\nhttp://article.gmane.org/gmane.comp.version-control.git/194230\n\nI also agreed, and so did Jonathan Nieder:\nhttp://article.gmane.org/gmane.comp.version-control.git/194950\n\nSo I don't see what you mean by those side \"discussions\" I recall\nJunio objecting to this, but the split was meant to solve another\nissue (zsh).\n\n> If it was so simple to just split __gitdir out, I think it would have\n> already been done.\n>\n>> The only slight issue is that __gitdir() would be duplicated, but this\n>> is probably not a big deal.\n>\n> That seems ugly. I know that splitting __gitdir out is also ugly, but\n> I know that there are going to be a lot more people who use git\n> completion than git_ps1. Consequently, in a duplicated __gitdir\n> scneario, I worry that __gitdir will receive more attention and may\n> relatively quickly diverge in implementation if not very careful in\n> approving patches. Moreover, a __gitdir of the future may not be\n> atomic and will pick up side effects and become impossible to manage\n> in two places.\n\nPerhaps, but it wouldn't work worst than the current __gitdir(). And I\nhaven't heard any better suggestions yet.\n\n> So maybe a split out \"git-gitdir.sh\" that both files include would be\n> \"better.\" Either that or the functionality of \"__gitdir\" gets pulled\n> into git itself. (perhaps a git-gitdir added to the main git\n> distribution)\n\nI like the idea of 'git gitdir' (or 'git dir'), and I dislike the idea\nof 'git-gitdir.sh'; people would need to copy one extra file, and\nprobably edit multiple files.\n\n>> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n>\n> As the patch is from you, there's no need to sign off on it too.\n\nYes I do, according to Linux guidelines[1], and that's what I've been\nalways doing in the git mailing list.\n\nAnyway, before going straight to a negative attitude, why don't we\nwait for more comments before making any conclusions?\n\nCheers.\n\n[1] http://www.kernel.org/doc/Documentation/SubmittingPatches\n\n-- \nFelipe Contreras\n"},{"id":"191976","messageId":"CAMP44s0X3G_eL6R4i+arLEPS3B5DzeXoFEqax_GDi-TQ+LVzFQ@mail.gmail.com","threadId":"30595","inReplyTo":"CAOnadRGBi0+Zno_eqzzkJjoUfXh=vEpEV5Cf_6zjOV42XPjXdg@mail.gmail.com","subject":"Re: [PATCH 2/2] completion: split __git_ps1 into a separate script","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2012-05-23T11:56:11Z","receivedAt":"2012-05-23T11:56:11Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Wed, May 23, 2012 at 12:29 AM, Ted Pavlic <ted@tedpavlic.com> wrote:\n>>>  create mode 100644 contrib/completion/git-prompt.sh\n>> Hi,\n>> since git-prompt is not completion related anymore, should a different\n>> directory be used?\n>\n> Making it even more likely that the __gitdir in one will someday not\n> match the __gitdir in another...\n\nWhich is not a big deal IMO. The \"bad\" __gitdir() won't get worst than\nthe current one.\n\n> Maybe __gitdir should live inside git-prompt and git-completion would\n> include git-prompt. That would make everything backward compatible\n> too. And that way there's a good answer to why git-prompt lives inside\n> the completion directory.\n\nThat's not bad, but still needs people to copy multiple scripts, and\nedit. I prefer to have a 'git dir' or something.\n\n-- \nFelipe Contreras\n"},{"id":"191977","messageId":"CAMP44s2DAFjtZY_s_h0GEMmDwwxApR1pwXVnfPP8S5bmauDkhQ@mail.gmail.com","threadId":"30595","inReplyTo":"4FBC0019.6030702@in.waw.pl","subject":"Re: [PATCH 2/2] completion: split __git_ps1 into a separate script","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2012-05-23T11:59:10Z","receivedAt":"2012-05-23T11:59:10Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Tue, May 22, 2012 at 11:07 PM, Zbigniew Jędrzejewski-Szmek\n<zbyszek@in.waw.pl> wrote:\n> On 05/22/2012 10:46 PM, Felipe Contreras wrote:\n>>  contrib/completion/git-completion.bash |  257 +---------------------------\n>>  contrib/completion/git-prompt.sh       |  287 ++++++++++++++++++++++++++++++++\n>>  t/t9903-bash-prompt.sh                 |    2 +-\n>>  3 files changed, 290 insertions(+), 256 deletions(-)\n>>  create mode 100644 contrib/completion/git-prompt.sh\n\n> since git-prompt is not completion related anymore, should a different\n> directory be used?\n\nThat's a good point. I personally wouldn't worry too much about this\nuntil there's a real issue. If we were to fix this, I would rather\nhave a 'shell' sub-directory and move everything there; I think have a\nsub-directory for 'completion' and another for 'prompt' would be\noverkill.\n\nUnfortunately this would mean packagers need to update.\n\nCheers.\n\n-- \nFelipe Contreras\n"},{"id":"191988","messageId":"7v4nr72bim.fsf@alter.siamese.dyndns.org","threadId":"30595","inReplyTo":"4FBC0019.6030702@in.waw.pl","subject":"Re: [PATCH 2/2] completion: split __git_ps1 into a separate script","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-05-23T14:54:41Z","receivedAt":"2012-05-23T14:54:41Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Zbigniew Jędrzejewski-Szmek  <zbyszek@in.waw.pl> writes:\n\n> On 05/22/2012 10:46 PM, Felipe Contreras wrote:\n>>  contrib/completion/git-completion.bash |  257 +---------------------------\n>>  contrib/completion/git-prompt.sh       |  287 ++++++++++++++++++++++++++++++++\n>>  t/t9903-bash-prompt.sh                 |    2 +-\n>>  3 files changed, 290 insertions(+), 256 deletions(-)\n>>  create mode 100644 contrib/completion/git-prompt.sh\n> Hi,\n> since git-prompt is not completion related anymore, should a different\n> directory be used?\n\nI am not sure if that is worth it.  These two share/duplicate some shell\nfunctions and we may end up refactoring them (a way to do so may be to\ndot-source git-prompt from git-completion and drop duplicated definitions\nfrom the latter), for example.\n"},{"id":"191989","messageId":"7vzk8z0wq7.fsf@alter.siamese.dyndns.org","threadId":"30595","inReplyTo":"CAMP44s0jLdNo89+c7+fBSokdxhCvPRnRKfhgVKnziMmv0vySXw@mail.gmail.com","subject":"Re: [PATCH 2/2] completion: split __git_ps1 into a separate script","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-05-23T14:59:28Z","receivedAt":"2012-05-23T14:59:28Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Felipe Contreras <felipe.contreras@gmail.com> writes:\n\n> On Wed, May 23, 2012 at 12:27 AM, Ted Pavlic <ted@tedpavlic.com> wrote:\n> ...\n>> Moreover, every time the subject of splitting __gitdir out comes up, a\n>> side discussion about all of the complications that could cause comes\n>> up... and people give up and hope that the folks upstream (i.e., here)\n>> will come up with a better solution.\n>\n> This is the reply Kerrick got to his suggestion from Jeff King:\n> http://article.gmane.org/gmane.comp.version-control.git/194230\n>\n> I also agreed, and so did Jonathan Nieder:\n> http://article.gmane.org/gmane.comp.version-control.git/194950\n>\n> So I don't see what you mean by those side \"discussions\" I recall\n> Junio objecting to this, but...\n\nA comment just on this part to avoid misunderstanding.  I do not recall\nobjecting to the above two articles, and after reading them again, I am\nhappy with the direction.  The message from me in the thread they are in\nwas merely me asking clarifications.\n"},{"id":"191994","messageId":"CAMP44s0aKi+8WHPXYLQ+iSMkj9iV88JGTabrpBRNBWb7upAMiQ@mail.gmail.com","threadId":"30595","inReplyTo":"7v4nr72bim.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH 2/2] completion: split __git_ps1 into a separate script","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2012-05-23T15:40:46Z","receivedAt":"2012-05-23T15:40:46Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Hi,\n\nOn Wed, May 23, 2012 at 4:54 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Zbigniew Jędrzejewski-Szmek  <zbyszek@in.waw.pl> writes:\n>\n>> On 05/22/2012 10:46 PM, Felipe Contreras wrote:\n>>>  contrib/completion/git-completion.bash |  257 +---------------------------\n>>>  contrib/completion/git-prompt.sh       |  287 ++++++++++++++++++++++++++++++++\n>>>  t/t9903-bash-prompt.sh                 |    2 +-\n>>>  3 files changed, 290 insertions(+), 256 deletions(-)\n>>>  create mode 100644 contrib/completion/git-prompt.sh\n>> Hi,\n>> since git-prompt is not completion related anymore, should a different\n>> directory be used?\n>\n> I am not sure if that is worth it.  These two share/duplicate some shell\n> functions and we may end up refactoring them (a way to do so may be to\n> dot-source git-prompt from git-completion and drop duplicated definitions\n> from the latter), for example.\n\nAnd how do you propose to update the install documentation?\n\n#    1) Copy this file to somewhere (e.g. ~/.git-completion.sh).\n#    2) Add the following line to your .bashrc/.zshrc:\n#        source ~/.git-completion.sh\n#\n#    3) Consider changing your PS1 to also show the current branch:\n\n1) Copy the file (e.g. ~/.git-completion.sh)\n2) Copy the other file (.e.g ~/.git-prompt.sh)\n3) Edit the original file (~/.git-completion.sh), modify the 'source'\ncommand to use the other file (~/.git-prompt.sh)\n\nAnd if the user doesn't care about prompt this certainly looks like overkill.\n\nWhat do we gain by this incredible user annoyance? Less maintenance\nburden of __gitdir() which barely changes anyway?\n\nWhat about 'git dir' or 'git info dir' (this could be used by other\nscripts to get information about various git commands, for completion,\ndocumentation, what not)?\n\nCheers.\n\n-- \nFelipe Contreras\n"},{"id":"192000","messageId":"7vk402272r.fsf@alter.siamese.dyndns.org","threadId":"30595","inReplyTo":"CAMP44s0aKi+8WHPXYLQ+iSMkj9iV88JGTabrpBRNBWb7upAMiQ@mail.gmail.com","subject":"Re: [PATCH 2/2] completion: split __git_ps1 into a separate script","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-05-23T16:30:36Z","receivedAt":"2012-05-23T16:30:36Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Felipe Contreras <felipe.contreras@gmail.com> writes:\n\n> And how do you propose to update the install documentation?\n>\n> #    1) Copy this file to somewhere (e.g. ~/.git-completion.sh).\n> #    2) Add the following line to your .bashrc/.zshrc:\n> #        source ~/.git-completion.sh\n> #\n> #    3) Consider changing your PS1 to also show the current branch:\n>\n> 1) Copy the file (e.g. ~/.git-completion.sh)\n> 2) Copy the other file (.e.g ~/.git-prompt.sh)\n> 3) Edit the original file (~/.git-completion.sh), modify the 'source'\n> command to use the other file (~/.git-prompt.sh)\n>\n> And if the user doesn't care about prompt this certainly looks like overkill.\n\nAgreed--the above would not fly.\n\n> What do we gain by this incredible user annoyance? Less maintenance\n> burden of __gitdir() which barely changes anyway?\n\nIf it lived in two separate projects, the pros-and-cons might be differnt\nbecause there will be cost for coordinating changes between the projects,\nbut I do not think \"barely changes\" is a good rationale to keep duplicates\nin this case, as we know both files come from the same project, and there\nis no release engineering cost to coordiate changes.  The only price we\npay by not removing the duplicates at the source level is the risk of two\ndrifting apart without anybody noticing, and that particular risk becomes\nthe more likely the less often the function changes.  In other words,\n\"barely changes\" is an argument _for_ removing duplicates.\n\nSplitting the definition of whatever is duplicated out to a separate file,\nhaving contrib/completion/Makefile insert it at an appropriate place in\nboth scripts at the build time, and driving that machinery from the\nMakefile at the top-level would be one possible way forward.  For people\nwho download and install from the source, the \"install insn\" could also be\nadded to the generated file to avoid confusion (and for people who just\nget the script(s) from their distro, the packagers would do that for\nthem).\n\nYou may think of a better solution to remove duplicates, of course, so I\nam not married to the \"have Makefile do it\" approach and am open to\nsuggestions.\n"},{"id":"192001","messageId":"7vd35u26yg.fsf@alter.siamese.dyndns.org","threadId":"30595","inReplyTo":"1337719600-7361-1-git-send-email-felipe.contreras@gmail.com","subject":"Re: [PATCH 0/2] completion: split into git-prompt.sh","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-05-23T16:33:11Z","receivedAt":"2012-05-23T16:33:11Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thanks for tying the loose ends.\n\nThe update to t9903 in the second patch is a bit tricky to handle, though.\nBy the time both series graduate, somebody has to tell t9903 where to find\nthe git-prompt scriptlet, but by basing it on 'pu', you made this series a\nhostage to the still-incomplete bash-prompt update series by SZEDER Gábor\n\nI think merging the bottom-most two commits in sg/bash-prompt series and\nthe tip of fc/git-complete-helper-fix and then applying these two patches\non top would be the easiest for me to handle, but if you or anybody else\nthink of a better organization, please speak up.\n\nThanks.\n"},{"id":"192007","messageId":"CAOnadRF8XyZKi+d=y1fFy2Xvs-3ETVyCbJBj83mK3Q8yuK7oQw@mail.gmail.com","threadId":"30595","inReplyTo":"CAMP44s0aKi+8WHPXYLQ+iSMkj9iV88JGTabrpBRNBWb7upAMiQ@mail.gmail.com","subject":"Re: [PATCH 2/2] completion: split __git_ps1 into a separate script","fromName":"Ted Pavlic","fromEmail":"ted@tedpavlic.com","sentAt":"2012-05-23T17:03:02Z","receivedAt":"2012-05-23T17:03:02Z","isPatch":true,"sender":{"key":"ted@tedpavlic.com","avatar":"https://gravatar.com/avatar/d085392370ff4c028cf17a0e81e0647744c9682fbcb36b499f31d08ef80ef569?d=mp&s=160"},"body":">> I am not sure if that is worth it.  These two share/duplicate some shell\n>> functions and we may end up refactoring them (a way to do so may be to\n>> dot-source git-prompt from git-completion and drop duplicated definitions\n>> from the latter), for example.\n>\n> And how do you propose to update the install documentation?\n>\n> 1) Copy the file (e.g. ~/.git-completion.sh)\n> 2) Copy the other file (.e.g ~/.git-prompt.sh)\n> 3) Edit the original file (~/.git-completion.sh), modify the 'source'\n> command to use the other file (~/.git-prompt.sh)\n\nThe third step doesn't seem necessary if .git-completion sources\ngit-prompt when it's available (and otherwise ignores it gracefully).\nThen anyone who cares about the prompt just makes sure that git-prompt\nis available.\n\n-- \nTed Pavlic <ted@tedpavlic.com>\n"},{"id":"192017","messageId":"CAMP44s3uW75O_jt2F7POxTAhX+qPyRSjOX9-DuEkg7a7WtnLsA@mail.gmail.com","threadId":"30595","inReplyTo":"CAOnadRF8XyZKi+d=y1fFy2Xvs-3ETVyCbJBj83mK3Q8yuK7oQw@mail.gmail.com","subject":"Re: [PATCH 2/2] completion: split __git_ps1 into a separate script","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2012-05-23T20:50:05Z","receivedAt":"2012-05-23T20:50:05Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Wed, May 23, 2012 at 7:03 PM, Ted Pavlic <ted@tedpavlic.com> wrote:\n>>> I am not sure if that is worth it.  These two share/duplicate some shell\n>>> functions and we may end up refactoring them (a way to do so may be to\n>>> dot-source git-prompt from git-completion and drop duplicated definitions\n>>> from the latter), for example.\n>>\n>> And how do you propose to update the install documentation?\n>>\n>> 1) Copy the file (e.g. ~/.git-completion.sh)\n>> 2) Copy the other file (.e.g ~/.git-prompt.sh)\n>> 3) Edit the original file (~/.git-completion.sh), modify the 'source'\n>> command to use the other file (~/.git-prompt.sh)\n>\n> The third step doesn't seem necessary if .git-completion sources\n> git-prompt when it's available (and otherwise ignores it gracefully).\n> Then anyone who cares about the prompt just makes sure that git-prompt\n> is available.\n\nAnd then anything that uses __gitdir() would fail.\n\nAnd how would you figure if it's available, and where it is available?\nWhat if git-completion.bash is distributed on\n/usr/share/bash-completion/completions/git? Where would you put\ngit-prompt.sh so it can be found *and* you would not require\nmodifications? And what if I want to put the latest version on\n~/.git-completion.sh (as the script actually suggests).\n\nThere's no way git-prompt.sh can be sourced without modifications to\nthe script, unless you expect it would always be named\n'.git-prompt.sh' and would be on the same directory, which many\ndistributions would frown upon.\n\n-- \nFelipe Contreras\n"},{"id":"192023","messageId":"4FBD5CC1.3060701@tedpavlic.com","threadId":"30595","inReplyTo":"CAMP44s3uW75O_jt2F7POxTAhX+qPyRSjOX9-DuEkg7a7WtnLsA@mail.gmail.com","subject":"Re: [PATCH 2/2] completion: split __git_ps1 into a separate script","fromName":"Ted Pavlic","fromEmail":"ted@tedpavlic.com","sentAt":"2012-05-23T21:55:13Z","receivedAt":"2012-05-23T21:55:13Z","isPatch":true,"sender":{"key":"ted@tedpavlic.com","avatar":"https://gravatar.com/avatar/d085392370ff4c028cf17a0e81e0647744c9682fbcb36b499f31d08ef80ef569?d=mp&s=160"},"body":"> There's no way git-prompt.sh can be sourced without modifications to\n> the script, unless you expect it would always be named\n> '.git-prompt.sh' and would be on the same directory, which many\n> distributions would frown upon.\n\nSo, again, seems like a good argument for building a git-gitdir into git\nproper. Maybe there are other utilities that could make use of it as\nwell...\n\n-- \nTed Pavlic <ted@tedpavlic.com>\n"},{"id":"192112","messageId":"20120524203549.GA2052@goldbirke","threadId":"30595","inReplyTo":"4FBD5CC1.3060701@tedpavlic.com","subject":"Re: [PATCH 2/2] completion: split __git_ps1 into a separate script","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2012-05-24T20:35:49Z","receivedAt":"2012-05-24T20:35:49Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"Hi,\n\n\nOn Wed, May 23, 2012 at 05:55:13PM -0400, Ted Pavlic wrote:\n> > There's no way git-prompt.sh can be sourced without modifications to\n> > the script, unless you expect it would always be named\n> > '.git-prompt.sh' and would be on the same directory, which many\n> > distributions would frown upon.\n> \n> So, again, seems like a good argument for building a git-gitdir into git\n> proper. Maybe there are other utilities that could make use of it as\n> well...\n\nYou mean a real git command, which does the same as __gitdir()?  I\ndon't like that, because it will always require 2 fork()s and an\nexec() and would be slow on Windows.\n\n\nBest,\nGábor\n"},{"id":"192116","messageId":"20120524204726.GB2052@goldbirke","threadId":"30595","inReplyTo":"1337719600-7361-3-git-send-email-felipe.contreras@gmail.com","subject":"Re: [PATCH 2/2] completion: split __git_ps1 into a separate script","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2012-05-24T20:47:26Z","receivedAt":"2012-05-24T20:47:26Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"\nHi,\n\n\nOn Tue, May 22, 2012 at 10:46:40PM +0200, Felipe Contreras wrote:\n> bash-completion 1.90 shipped \n\nThat's still beta, right?  (or the bash-completion website is out of\ndate...)\n\n> with support to load completions\n> dynamically[1], which means the git completion script wouldn't be loaded\n> until the user types 'git <tab>'--this creates a problem to people using\n> __git_ps1(); that function won't be available when the shell is first\n> created.\n> \n> For now distributions have workarounded this issue by moving the git\n> completion to the \"compatdir\"[2]; this of course is not ideal.\n> \n> The solution, proposed by Kerrick Staley[3], is to split the git script\n> in two; the part that deals with __git_ps1() in one (i.e.\n> git-prompt.sh), and everything else in another (i.e.\n> git-completion.bash).\n\nThis breaks existing setups, where the user installs\ngit-completion.bash with 'make install', or where the user sources\ngit-completion.bash directly from the repository.\n\n\nBest,\nGábor\n"},{"id":"192117","messageId":"20120524204948.GA9028@goldbirke","threadId":"30595","inReplyTo":"CAMP44s0aKi+8WHPXYLQ+iSMkj9iV88JGTabrpBRNBWb7upAMiQ@mail.gmail.com","subject":"Re: [PATCH 2/2] completion: split __git_ps1 into a separate script","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2012-05-24T20:49:48Z","receivedAt":"2012-05-24T20:49:48Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Wed, May 23, 2012 at 05:40:46PM +0200, Felipe Contreras wrote:\n> What do we gain by this incredible user annoyance? Less maintenance\n> burden of __gitdir() which barely changes anyway?\n\nI happen to have a topic in the works which changes __gitdir() and\nadds some helper functions to it, so the diffstat of all\n__gitdir()-related changes is this:\n\n 1 file changed, 71 insertions(+), 6 deletions(-)\n\n\nGábor\n"},{"id":"192154","messageId":"20120525073506.GD2052@goldbirke","threadId":"30595","inReplyTo":"CAOnadRFbrhrFz7Ya3Vhgsju9G723Qu0OdJnM31xFmBqQNgj6gA@mail.gmail.com","subject":"Re: [PATCH 2/2] completion: split __git_ps1 into a separate script","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2012-05-25T07:35:06Z","receivedAt":"2012-05-25T07:35:06Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Thu, May 24, 2012 at 11:36:45PM -0400, Ted Pavlic wrote:\n> > You mean a real git command, which does the same as __gitdir()?  I\n> > don't like that, because it will always require 2 fork()s and an\n> > exec() and would be slow on Windows.\n> \n> Interesting. I guess I didn't realize bash completion was an issue for most\n> Windows users. Is it?\n\nIt is.  Emulating fork() and exec() is very expensive, so every\nsubshell, external command, or especially git command in a command\nsubstitution costs dearly.  And the completion script uses many git\ncommands and even more subshells.\n\nCase in point is __git_ps1() and __gitdir().  There are scenarios\nwhere displaying the git-specific bash prompt takes more than 400ms on\nWindows, while displaying the same prompt takes only about 26ms on\nLinux on the same hardware.\n\n  http://thread.gmane.org/gmane.comp.version-control.git/197432\n\n\nBest,\nGábor\n"},{"id":"192155","messageId":"87ehq8its8.fsf@thomas.inf.ethz.ch","threadId":"30595","inReplyTo":"20120525073506.GD2052@goldbirke","subject":"Re: [PATCH 2/2] completion: split __git_ps1 into a separate script","fromName":"Thomas Rast","fromEmail":"trast@inf.ethz.ch","sentAt":"2012-05-25T07:50:15Z","receivedAt":"2012-05-25T07:50:15Z","isPatch":true,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"SZEDER Gábor <szeder@ira.uka.de> writes:\n\n> On Thu, May 24, 2012 at 11:36:45PM -0400, Ted Pavlic wrote:\n>> > You mean a real git command, which does the same as __gitdir()?  I\n>> > don't like that, because it will always require 2 fork()s and an\n>> > exec() and would be slow on Windows.\n>> \n>> Interesting. I guess I didn't realize bash completion was an issue for most\n>> Windows users. Is it?\n>\n> It is.  Emulating fork() and exec() is very expensive, so every\n> subshell, external command, or especially git command in a command\n> substitution costs dearly.  And the completion script uses many git\n> commands and even more subshells.\n>\n> Case in point is __git_ps1() and __gitdir().  There are scenarios\n> where displaying the git-specific bash prompt takes more than 400ms on\n> Windows, while displaying the same prompt takes only about 26ms on\n> Linux on the same hardware.\n>\n>   http://thread.gmane.org/gmane.comp.version-control.git/197432\n\nWhy not make a git builtin command that figures out everything that\n__git_ps1 does?  Perhaps in a format that can be eval'd and processed to\nthe user's taste.\n\n-- \nThomas Rast\ntrast@{inf,student}.ethz.ch\n"},{"id":"192158","messageId":"CAMP44s185ZyFQRNkbKq840zEMopup4EPSUSKFzF5ZaZbP0Te7w@mail.gmail.com","threadId":"30595","inReplyTo":"87ehq8its8.fsf@thomas.inf.ethz.ch","subject":"Re: [PATCH 2/2] completion: split __git_ps1 into a separate script","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2012-05-25T10:01:25Z","receivedAt":"2012-05-25T10:01:25Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Fri, May 25, 2012 at 9:50 AM, Thomas Rast <trast@inf.ethz.ch> wrote:\n> SZEDER Gábor <szeder@ira.uka.de> writes:\n>\n>> On Thu, May 24, 2012 at 11:36:45PM -0400, Ted Pavlic wrote:\n>>> > You mean a real git command, which does the same as __gitdir()?  I\n>>> > don't like that, because it will always require 2 fork()s and an\n>>> > exec() and would be slow on Windows.\n>>>\n>>> Interesting. I guess I didn't realize bash completion was an issue for most\n>>> Windows users. Is it?\n>>\n>> It is.  Emulating fork() and exec() is very expensive, so every\n>> subshell, external command, or especially git command in a command\n>> substitution costs dearly.  And the completion script uses many git\n>> commands and even more subshells.\n>>\n>> Case in point is __git_ps1() and __gitdir().  There are scenarios\n>> where displaying the git-specific bash prompt takes more than 400ms on\n>> Windows, while displaying the same prompt takes only about 26ms on\n>> Linux on the same hardware.\n>>\n>>   http://thread.gmane.org/gmane.comp.version-control.git/197432\n>\n> Why not make a git builtin command that figures out everything that\n> __git_ps1 does?  Perhaps in a format that can be eval'd and processed to\n> the user's taste.\n\nThat is what I was thinking.\n\n-- \nFelipe Contreras\n"},{"id":"192180","messageId":"4FBFC6A9.1050209@iki.fi","threadId":"30595","inReplyTo":"20120524204726.GB2052@goldbirke","subject":"Re: [PATCH 2/2] completion: split __git_ps1 into a separate script","fromName":"Ville Skyttä","fromEmail":"ville.skytta@iki.fi","sentAt":"2012-05-25T17:51:37Z","receivedAt":"2012-05-25T17:51:37Z","isPatch":true,"sender":{"key":"ville.skytta@iki.fi","avatar":"https://avatars.githubusercontent.com/u/109152?v=4"},"body":"On 2012-05-24 23:47, SZEDER Gábor wrote:\n> \n> On Tue, May 22, 2012 at 10:46:40PM +0200, Felipe Contreras wrote:\n>> bash-completion 1.90 shipped \n> \n> That's still beta, right?  (or the bash-completion website is out of\n> date...)\n\n1.99 has been out since January, and the website has also mentioned it\nsince then.  1.99 is a beta or a release candidate if you prefer, but\npersonally I believe it's very close to 2.0 at least in terms of things\nbeing discussed in this thread.\n"},{"id":"192182","messageId":"7v8vggt9y5.fsf@alter.siamese.dyndns.org","threadId":"30595","inReplyTo":"87ehq8its8.fsf@thomas.inf.ethz.ch","subject":"Re: [PATCH 2/2] completion: split __git_ps1 into a separate script","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-05-25T18:03:14Z","receivedAt":"2012-05-25T18:03:14Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thomas Rast <trast@inf.ethz.ch> writes:\n\n> Why not make a git builtin command that figures out everything that\n> __git_ps1 does?  Perhaps in a format that can be eval'd and processed to\n> the user's taste.\n\nI'd rather not to see something so specific for one interpreter like that\nin the core.  How about doing it this way instead?\n\ndiff --git a/contrib/completion/Makefile b/contrib/completion/Makefile\nnew file mode 100644\nindex 0000000..71c600f\n--- /dev/null\n+++ b/contrib/completion/Makefile\n@@ -0,0 +1,13 @@\n+# The default target is ...\n+all::\n+\n+SCRIPTS = git-completion.bash git-prompt.sh\n+\n+all:: $(SCRIPTS)\n+clean::\n+\trm -f $(SCRIPTS)\n+\n+$(SCRIPTS): % : %.shc\n+\trm -f $@+ $@\n+\tsed -e '/## include common-bits/r common-bits' $< >$@+\n+\tmv $@+ $@\ndiff --git a/contrib/completion/common-bits b/contrib/completion/common-bits\nnew file mode 100644\nindex 0000000..06c2845\n--- /dev/null\n+++ b/contrib/completion/common-bits\n@@ -0,0 +1,22 @@\n+# __gitdir accepts 0 or 1 arguments (i.e., location)\n+# returns location of .git repo\n+__gitdir ()\n+{\n+\tif [ -z \"${1-}\" ]; then\n+\t\tif [ -n \"${__git_dir-}\" ]; then\n+\t\t\techo \"$__git_dir\"\n+\t\telif [ -n \"${GIT_DIR-}\" ]; then\n+\t\t\ttest -d \"${GIT_DIR-}\" || return 1\n+\t\t\techo \"$GIT_DIR\"\n+\t\telif [ -d .git ]; then\n+\t\t\techo .git\n+\t\telse\n+\t\t\tgit rev-parse --git-dir 2>/dev/null\n+\t\tfi\n+\telif [ -d \"$1/.git\" ]; then\n+\t\techo \"$1/.git\"\n+\telse\n+\t\techo \"$1\"\n+\tfi\n+}\n+\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash.shc\nsimilarity index 99%\nrename from contrib/completion/git-completion.bash\nrename to contrib/completion/git-completion.bash.shc\nindex abf8215..cf30f01 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash.shc\n@@ -32,24 +32,8 @@ case \"$COMP_WORDBREAKS\" in\n *)   COMP_WORDBREAKS=\"$COMP_WORDBREAKS:\"\n esac\n \n-# __gitdir accepts 0 or 1 arguments (i.e., location)\n-# returns location of .git repo\n-__gitdir ()\n-{\n-\tif [ -z \"${1-}\" ]; then\n-\t\tif [ -n \"${__git_dir-}\" ]; then\n-\t\t\techo \"$__git_dir\"\n-\t\telif [ -d .git ]; then\n-\t\t\techo .git\n-\t\telse\n-\t\t\tgit rev-parse --git-dir 2>/dev/null\n-\t\tfi\n-\telif [ -d \"$1/.git\" ]; then\n-\t\techo \"$1/.git\"\n-\telse\n-\t\techo \"$1\"\n-\tfi\n-}\n+## include common-bits here\n+## common-bits ends here\n \n __gitcomp_1 ()\n {\ndiff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh.shc\nsimilarity index 94%\nrename from contrib/completion/git-prompt.sh\nrename to contrib/completion/git-prompt.sh.shc\nindex 8e2e9f3..d442a1a 100644\n--- a/contrib/completion/git-prompt.sh\n+++ b/contrib/completion/git-prompt.sh.shc\n@@ -49,27 +49,8 @@\n # GIT_PS1_SHOWUPSTREAM, you can override it on a per-repository basis by\n # setting the bash.showUpstream config variable.\n \n-# __gitdir accepts 0 or 1 arguments (i.e., location)\n-# returns location of .git repo\n-__gitdir ()\n-{\n-\tif [ -z \"${1-}\" ]; then\n-\t\tif [ -n \"${__git_dir-}\" ]; then\n-\t\t\techo \"$__git_dir\"\n-\t\telif [ -n \"${GIT_DIR-}\" ]; then\n-\t\t\ttest -d \"${GIT_DIR-}\" || return 1\n-\t\t\techo \"$GIT_DIR\"\n-\t\telif [ -d .git ]; then\n-\t\t\techo .git\n-\t\telse\n-\t\t\tgit rev-parse --git-dir 2>/dev/null\n-\t\tfi\n-\telif [ -d \"$1/.git\" ]; then\n-\t\techo \"$1/.git\"\n-\telse\n-\t\techo \"$1\"\n-\tfi\n-}\n+## include common-bits here\n+## common-bits ends here\n \n # stores the divergence from upstream in $p\n # used by GIT_PS1_SHOWUPSTREAM\n"},{"id":"201831","messageId":"20121025005106.GA9112@elie.Belkin","threadId":"30595","inReplyTo":"1337719600-7361-3-git-send-email-felipe.contreras@gmail.com","subject":"Where should git-prompt.sh be installed?","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2012-10-25T00:51:06Z","receivedAt":"2012-10-25T00:51:06Z","isPatch":false,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Hi,\n\nIn olden days the admin would copy contrib/completion/git-completion.sh\nto\n\n        /etc/bash_completion.d/git\n\nand mortals could source /etc/bash_completion or\n/etc/bash_completion.d/git in their ~/.bashrc (possibly shared among\nmultiple machines) so that the bash completion and __git_ps1 helpers\ncould work.\n\nWith Git 1.7.12 __git_ps1 has been split into a separate file, to help\nusers who only want __git_ps1 to avoid the overhead of loading the\nentire completion script (and allow the completion script to be loaded\nby bash-completion magic on the fly!).  Now the sysadmin should copy\ncontrib/completion/git-completion.sh to\n\n\t/usr/share/bash-completion/completions/git\n\nand contrib/completion/git-prompt.sh to\n\n\t/usr/share/git-core/contrib/?? (somewhere?)\n\nMortals source /etc/bash_completion in their ~/.bashrc (possibly\nshared among multiple machines) and expect bash completion to work.\nFor __git_ps1, users should source that ?? path.\n\nQuestions:\n\n 1) what path is appropriate for ?? above?\n 2) is this documented anywhere?\n\nPossible answers:\n\n 1) Fedora uses /etc/profile.d/git-prompt.sh.  Gentoo uses\n    /usr/share/bash-completion/git-prompt.  Maybe others use\n    some other path.\n\n 2) The scripts themselves suggest copying to ~/.git-completion.sh\n    and ~/.git-prompt.sh.\n\nProposal:\n\n  1) /usr/lib/git-core/git-sh-prompt\n  2) git-sh-prompt(1)\n\nSensible?\n\nThanks,\nJonathan\n"},{"id":"201836","messageId":"CAM9Z-nnqG2Gm_9T1k25yYHWGtyS3MSBzJW31XiizsCHa=Pc59A@mail.gmail.com","threadId":"30595","inReplyTo":"20121025005106.GA9112@elie.Belkin","subject":"Re: Where should git-prompt.sh be installed?","fromName":"Drew Northup","fromEmail":"n1xim.email@gmail.com","sentAt":"2012-10-25T01:59:31Z","receivedAt":"2012-10-25T01:59:31Z","isPatch":false,"sender":{"key":"n1xim.email@gmail.com","avatar":null},"body":"On Wed, Oct 24, 2012 at 8:51 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:\n> Now the sysadmin should copy\n> contrib/completion/git-completion.sh to\n>\n>         /usr/share/bash-completion/completions/git\n>\n> and contrib/completion/git-prompt.sh to\n>\n>         /usr/share/git-core/contrib/?? (somewhere?)\n>\n> Mortals source /etc/bash_completion in their ~/.bashrc (possibly\n> shared among multiple machines) and expect bash completion to work.\n> For __git_ps1, users should source that ?? path.\n>\n> Questions:\n>\n>  1) what path is appropriate for ?? above?\n>  2) is this documented anywhere?\n>\n> Possible answers:\n>\n>  1) Fedora uses /etc/profile.d/git-prompt.sh.  Gentoo uses\n>     /usr/share/bash-completion/git-prompt.  Maybe others use\n>     some other path.\n>\n>  2) The scripts themselves suggest copying to ~/.git-completion.sh\n>     and ~/.git-prompt.sh.\n>\n> Proposal:\n>\n>   1) /usr/lib/git-core/git-sh-prompt\n>   2) git-sh-prompt(1)\n>\n> Sensible?\n\nDoes the LSB provide any guidance? If not, or if such guidance isn't\nhelpful, I say that looks reasonable.\n\nWhat I'd like to know is why we are saying \"copy\" when symlinking is\nlikely to be more easily maintainable? (Less chance to screw up.)\n\n-- \n-Drew Northup\n--------------------------------------------------------------\n\"As opposed to vegetable or mineral error?\"\n-John Pescatore, SANS NewsBites Vol. 12 Num. 59\n"},{"id":"201851","messageId":"3B606942-D194-4148-AF6E-1F3283C983ED@googlemail.com","threadId":"30595","inReplyTo":"20121025005106.GA9112@elie.Belkin","subject":"Re: Where should git-prompt.sh be installed?","fromName":"Danny Yates","fromEmail":"mail4danny@gmail.com","sentAt":"2012-10-25T06:02:27Z","receivedAt":"2012-10-25T06:02:27Z","isPatch":false,"sender":{"key":"mail4danny@gmail.com","avatar":null},"body":"Would that not give the impression of \"git sh-prompt\" being a core command? If so, that would be poor, IMHO. \n\nWhen I was investigating this last night, I expected to find it (git-prompt.sh) in contrib, although that doesn't make an enormous amount of sense. Ideally, the full path to wherever it's installed should be mentioned in the bash completion file (which is where I went to look when __git_ps1 stopped working), but that would mean modifying a file from upstream and I'm not sure if that's easy/\"the done thing\".\n\nDanny. \n\n\nOn 25 Oct 2012, at 01:51, Jonathan Nieder <jrnieder@gmail.com> wrote:\n\n> Hi,\n> \n> In olden days the admin would copy contrib/completion/git-completion.sh\n> to\n> \n>        /etc/bash_completion.d/git\n> \n> and mortals could source /etc/bash_completion or\n> /etc/bash_completion.d/git in their ~/.bashrc (possibly shared among\n> multiple machines) so that the bash completion and __git_ps1 helpers\n> could work.\n> \n> With Git 1.7.12 __git_ps1 has been split into a separate file, to help\n> users who only want __git_ps1 to avoid the overhead of loading the\n> entire completion script (and allow the completion script to be loaded\n> by bash-completion magic on the fly!).  Now the sysadmin should copy\n> contrib/completion/git-completion.sh to\n> \n>    /usr/share/bash-completion/completions/git\n> \n> and contrib/completion/git-prompt.sh to\n> \n>    /usr/share/git-core/contrib/?? (somewhere?)\n> \n> Mortals source /etc/bash_completion in their ~/.bashrc (possibly\n> shared among multiple machines) and expect bash completion to work.\n> For __git_ps1, users should source that ?? path.\n> \n> Questions:\n> \n> 1) what path is appropriate for ?? above?\n> 2) is this documented anywhere?\n> \n> Possible answers:\n> \n> 1) Fedora uses /etc/profile.d/git-prompt.sh.  Gentoo uses\n>    /usr/share/bash-completion/git-prompt.  Maybe others use\n>    some other path.\n> \n> 2) The scripts themselves suggest copying to ~/.git-completion.sh\n>    and ~/.git-prompt.sh.\n> \n> Proposal:\n> \n>  1) /usr/lib/git-core/git-sh-prompt\n>  2) git-sh-prompt(1)\n> \n> Sensible?\n> \n> Thanks,\n> Jonathan\n"},{"id":"201861","messageId":"20121025074549.GC15790@elie.Belkin","threadId":"30595","inReplyTo":"3B606942-D194-4148-AF6E-1F3283C983ED@googlemail.com","subject":"[RFC/PATCH] __git_ps1: migrate out of contrib/completion","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2012-10-25T07:45:49Z","receivedAt":"2012-10-25T07:45:49Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Different installers put the git-prompt.sh shell library at different\nplaces on the installed system, so there is no shared location users\ncan count on:\n\n  Fedora - /etc/profile.d/git-prompt.sh\n  Gentoo - /usr/share/bash-completion/git-prompt\n  Arch - /usr/share/git/git-prompt.sh\n\nThe __git_ps1 helper doesn't have anything to do with bash completion\nin principle, but because it was written in the context of that\nproject, its sources are kept in contrib/completion/git-prompt.sh.\nLet's make it a first-class shell library in the toplevel and install\nit to $(gitexecdir) alongside git-sh-setup and git-sh-i18n, where it\ncan be easily found.\n\nKeep a symlink in contrib/completion/ to avoid breaking setups where\nthis library is used directly from the source tree.\n\nNow you can put the following in your ~/.bashrc:\n\n\tif test \"${BASH+set}\" && test \"${PS1+set}\"\t# interactive!\n\tthen\n\t\tgitexecdir=$(git --exec-path)\n\t\tif test -r \"$gitexecdir/git-sh-prompt)\"\n\t\tthen\n\t\t\t. \"$gitexecdir/git-sh-prompt\"\n\t\tfi\n\t\tif type -t __git_ps1 >/dev/null\n\t\tthen\n\t\t\tPS1='\\w$(__git_ps1)\\$ '\n\t\tfi\n\tfi\n\nand the shell prompt will show the current branch name in git\nrepositories when on a machine with a new enough version of git.\n\nReported-by: Danny Yates <mail4danny@googlemail.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\nDanny Yates wrote:\n\n> Would that not give the impression of \"git sh-prompt\" being a core\n> command? If so, that would be poor, IMHO. \n\nNot any more than $(git --exec-path)/git-sh-setup and git-sh-i18n. :)\n\n> When I was investigating this last night, I expected to find it\n> (git-prompt.sh) in contrib, although that doesn't make an enormous\n> amount of sense. Ideally, the full path to wherever it's installed\n> should be mentioned in the bash completion file (which is where I\n> went to look when __git_ps1 stopped working),\n\nYes, certainly.\n\n>                                               but that would mean\n> modifying a file from upstream and I'm not sure if that's easy/\"the\n> done thing\".\n\nWe're talking on the upstream list now, so that's not an issue.\n\nThanks,\nJonathan\n\n Documentation/git-sh-prompt.txt                    |  79 ++++++\n Makefile                                           |   1 +\n contrib/completion/git-completion.bash             |   2 +-\n contrib/completion/git-prompt.sh                   | 291 +--------------------\n .../completion/git-prompt.sh => git-sh-prompt.sh   |   0\n 5 files changed, 82 insertions(+), 291 deletions(-)\n create mode 100644 Documentation/git-sh-prompt.txt\n rewrite contrib/completion/git-prompt.sh (100%)\n mode change 100644 => 120000\n rename contrib/completion/git-prompt.sh => git-sh-prompt.sh (100%)\n\ndiff --git a/Documentation/git-sh-prompt.txt b/Documentation/git-sh-prompt.txt\nnew file mode 100644\nindex 00000000..2c705fef\n--- /dev/null\n+++ b/Documentation/git-sh-prompt.txt\n@@ -0,0 +1,79 @@\n+git-sh-prompt(1)\n+================\n+\n+NAME\n+----\n+git-sh-prompt - Functions to describe repository in bash or zsh prompt\n+\n+SYNOPSIS\n+--------\n+[verse]\n+'. \"$(git --exec-path)/git-sh-prompt\"'\n+\n+DESCRIPTION\n+-----------\n+This script allows you to see the current branch in your bash prompt.\n+\n+To enable:\n+\n+1. Add the following line to your .bashrc and .zshrc:\n+\n+\t. \"$(git --exec-path)/git-sh-prompt\"\n+\n+2. Change your PS1 to also show the current branch:\n+\n+\tBash: PS1='[\\u@\\h \\W$(__git_ps1 \" (%s)\")]\\$ '\n+\tZsh:  PS1='[%n@%m %c$(__git_ps1 \" (%s)\")]\\$ '\n+\n+The argument to __git_ps1 will only be displayed if you are currently\n+in a git repository.  The %s token is replaced by the name of the current\n+branch.\n+\n+In addition, if you set GIT_PS1_SHOWDIRTYSTATE to a nonempty value,\n+unstaged (`*`) and staged (`+`) changes are indicated next to the branch\n+name. You can configure this per repository with the `bash.showDirtyState`\n+variable, which defaults to `true` once GIT_PS1_SHOWDIRTYSTATE is enabled.\n+\n+You can also see if something is currently stashed, by setting\n+GIT_PS1_SHOWSTASHSTATE to a nonempty value. If something is stashed,\n+then a '$' is shown next to the branch name.\n+\n+If you would like to see if there are untracked files, set\n+GIT_PS1_SHOWUNTRACKEDFILES to a nonempty value.  If there are untracked\n+files, a '%' is shown next to the branch name.\n+\n+If you would like to see the difference between HEAD and its upstream,\n+set GIT_PS1_SHOWUPSTREAM=auto.  A '<' indicates the current branch is\n+behind, '>' indicates it is ahead, '<>' indicates it has diverged, and\n+'=' indicates no difference.  You can further control behavior by\n+setting GIT_PS1_SHOWUPSTREAM to a space-separated list of values:\n+\n+verbose::\n+\tshow number of commits ahead of/behind (+/-) upstream\n+legacy::\n+\tdon't use the '--count' option available in recent versions\n+\tof git-rev-list\n+git::\n+\talways compare HEAD to `@{upstream}`\n+svn::\n+\talways compare HEAD to your 'git svn' upstream\n+\n+By default, __git_ps1 compares HEAD to your 'git svn' upstream if it can\n+find one, or `@{upstream}` otherwise.  Once you have set GIT_PS1_SHOWUPSTREAM,\n+you can override it on a per-repository basis by setting the `bash.showUpstream`\n+config variable.\n+\n+FUNCTIONS\n+---------\n+\n+'__gitdir' [<directory>]::\n+\tPrint the path to the git repository (`.git` directory).  This is\n+\tsimilar to `git rev-parse --git-dir` but it is faster because it avoids\n+\tforking a new process when possible.\n+\n+'__git_ps1_show_upstream'::\n+\tInternal function.\n+\n+'__git_ps1 [<format>]'::\n+\tPrint text to add to the shell's PS1 prompt, including the current\n+\tbranch name.  If <format> is not specified, it defaults to \" (%s)\".\ndiff --git a/Makefile b/Makefile\nindex f69979e3..c12d973b 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -459,6 +459,7 @@ SCRIPT_LIB += git-rebase--interactive\n SCRIPT_LIB += git-rebase--merge\n SCRIPT_LIB += git-sh-setup\n SCRIPT_LIB += git-sh-i18n\n+SCRIPT_LIB += git-sh-prompt\n \n SCRIPT_PERL += git-add--interactive.perl\n SCRIPT_PERL += git-difftool.perl\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex be800e09..01238588 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -21,7 +21,7 @@\n #    2) Add the following line to your .bashrc/.zshrc:\n #        source ~/.git-completion.sh\n #    3) Consider changing your PS1 to also show the current branch,\n-#       see git-prompt.sh for details.\n+#       see git-sh-prompt(1) for details.\n \n if [[ -n ${ZSH_VERSION-} ]]; then\n \tautoload -U +X bashcompinit && bashcompinit\ndiff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\ndeleted file mode 100644\nindex bf20491e..00000000\n--- a/contrib/completion/git-prompt.sh\n+++ /dev/null\n@@ -1,290 +0,0 @@\n-# bash/zsh git prompt support\n-#\n-# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>\n-# Distributed under the GNU General Public License, version 2.0.\n-#\n-# This script allows you to see the current branch in your prompt.\n-#\n-# To enable:\n-#\n-#    1) Copy this file to somewhere (e.g. ~/.git-prompt.sh).\n-#    2) Add the following line to your .bashrc/.zshrc:\n-#        source ~/.git-prompt.sh\n-#    3) Change your PS1 to also show the current branch:\n-#         Bash: PS1='[\\u@\\h \\W$(__git_ps1 \" (%s)\")]\\$ '\n-#         ZSH:  PS1='[%n@%m %c$(__git_ps1 \" (%s)\")]\\$ '\n-#\n-# The argument to __git_ps1 will be displayed only if you are currently\n-# in a git repository.  The %s token will be the name of the current\n-# branch.\n-#\n-# In addition, if you set GIT_PS1_SHOWDIRTYSTATE to a nonempty value,\n-# unstaged (*) and staged (+) changes will be shown next to the branch\n-# name.  You can configure this per-repository with the\n-# bash.showDirtyState variable, which defaults to true once\n-# GIT_PS1_SHOWDIRTYSTATE is enabled.\n-#\n-# You can also see if currently something is stashed, by setting\n-# GIT_PS1_SHOWSTASHSTATE to a nonempty value. If something is stashed,\n-# then a '$' will be shown next to the branch name.\n-#\n-# If you would like to see if there're untracked files, then you can set\n-# GIT_PS1_SHOWUNTRACKEDFILES to a nonempty value. If there're untracked\n-# files, then a '%' will be shown next to the branch name.\n-#\n-# If you would like to see the difference between HEAD and its upstream,\n-# set GIT_PS1_SHOWUPSTREAM=\"auto\".  A \"<\" indicates you are behind, \">\"\n-# indicates you are ahead, \"<>\" indicates you have diverged and \"=\"\n-# indicates that there is no difference. You can further control\n-# behaviour by setting GIT_PS1_SHOWUPSTREAM to a space-separated list\n-# of values:\n-#\n-#     verbose       show number of commits ahead/behind (+/-) upstream\n-#     legacy        don't use the '--count' option available in recent\n-#                   versions of git-rev-list\n-#     git           always compare HEAD to @{upstream}\n-#     svn           always compare HEAD to your SVN upstream\n-#\n-# By default, __git_ps1 will compare HEAD to your SVN upstream if it can\n-# find one, or @{upstream} otherwise.  Once you have set\n-# GIT_PS1_SHOWUPSTREAM, you can override it on a per-repository basis by\n-# setting the bash.showUpstream config variable.\n-\n-# __gitdir accepts 0 or 1 arguments (i.e., location)\n-# returns location of .git repo\n-__gitdir ()\n-{\n-\t# Note: this function is duplicated in git-completion.bash\n-\t# When updating it, make sure you update the other one to match.\n-\tif [ -z \"${1-}\" ]; then\n-\t\tif [ -n \"${__git_dir-}\" ]; then\n-\t\t\techo \"$__git_dir\"\n-\t\telif [ -n \"${GIT_DIR-}\" ]; then\n-\t\t\ttest -d \"${GIT_DIR-}\" || return 1\n-\t\t\techo \"$GIT_DIR\"\n-\t\telif [ -d .git ]; then\n-\t\t\techo .git\n-\t\telse\n-\t\t\tgit rev-parse --git-dir 2>/dev/null\n-\t\tfi\n-\telif [ -d \"$1/.git\" ]; then\n-\t\techo \"$1/.git\"\n-\telse\n-\t\techo \"$1\"\n-\tfi\n-}\n-\n-# stores the divergence from upstream in $p\n-# used by GIT_PS1_SHOWUPSTREAM\n-__git_ps1_show_upstream ()\n-{\n-\tlocal key value\n-\tlocal svn_remote svn_url_pattern count n\n-\tlocal upstream=git legacy=\"\" verbose=\"\"\n-\n-\tsvn_remote=()\n-\t# get some config options from git-config\n-\tlocal output=\"$(git config -z --get-regexp '^(svn-remote\\..*\\.url|bash\\.showupstream)$' 2>/dev/null | tr '\\0\\n' '\\n ')\"\n-\twhile read -r key value; do\n-\t\tcase \"$key\" in\n-\t\tbash.showupstream)\n-\t\t\tGIT_PS1_SHOWUPSTREAM=\"$value\"\n-\t\t\tif [[ -z \"${GIT_PS1_SHOWUPSTREAM}\" ]]; then\n-\t\t\t\tp=\"\"\n-\t\t\t\treturn\n-\t\t\tfi\n-\t\t\t;;\n-\t\tsvn-remote.*.url)\n-\t\t\tsvn_remote[ $((${#svn_remote[@]} + 1)) ]=\"$value\"\n-\t\t\tsvn_url_pattern+=\"\\\\|$value\"\n-\t\t\tupstream=svn+git # default upstream is SVN if available, else git\n-\t\t\t;;\n-\t\tesac\n-\tdone <<< \"$output\"\n-\n-\t# parse configuration values\n-\tfor option in ${GIT_PS1_SHOWUPSTREAM}; do\n-\t\tcase \"$option\" in\n-\t\tgit|svn) upstream=\"$option\" ;;\n-\t\tverbose) verbose=1 ;;\n-\t\tlegacy)  legacy=1  ;;\n-\t\tesac\n-\tdone\n-\n-\t# Find our upstream\n-\tcase \"$upstream\" in\n-\tgit)    upstream=\"@{upstream}\" ;;\n-\tsvn*)\n-\t\t# get the upstream from the \"git-svn-id: ...\" in a commit message\n-\t\t# (git-svn uses essentially the same procedure internally)\n-\t\tlocal svn_upstream=($(git log --first-parent -1 \\\n-\t\t\t\t\t--grep=\"^git-svn-id: \\(${svn_url_pattern#??}\\)\" 2>/dev/null))\n-\t\tif [[ 0 -ne ${#svn_upstream[@]} ]]; then\n-\t\t\tsvn_upstream=${svn_upstream[ ${#svn_upstream[@]} - 2 ]}\n-\t\t\tsvn_upstream=${svn_upstream%@*}\n-\t\t\tlocal n_stop=\"${#svn_remote[@]}\"\n-\t\t\tfor ((n=1; n <= n_stop; n++)); do\n-\t\t\t\tsvn_upstream=${svn_upstream#${svn_remote[$n]}}\n-\t\t\tdone\n-\n-\t\t\tif [[ -z \"$svn_upstream\" ]]; then\n-\t\t\t\t# default branch name for checkouts with no layout:\n-\t\t\t\tupstream=${GIT_SVN_ID:-git-svn}\n-\t\t\telse\n-\t\t\t\tupstream=${svn_upstream#/}\n-\t\t\tfi\n-\t\telif [[ \"svn+git\" = \"$upstream\" ]]; then\n-\t\t\tupstream=\"@{upstream}\"\n-\t\tfi\n-\t\t;;\n-\tesac\n-\n-\t# Find how many commits we are ahead/behind our upstream\n-\tif [[ -z \"$legacy\" ]]; then\n-\t\tcount=\"$(git rev-list --count --left-right \\\n-\t\t\t\t\"$upstream\"...HEAD 2>/dev/null)\"\n-\telse\n-\t\t# produce equivalent output to --count for older versions of git\n-\t\tlocal commits\n-\t\tif commits=\"$(git rev-list --left-right \"$upstream\"...HEAD 2>/dev/null)\"\n-\t\tthen\n-\t\t\tlocal commit behind=0 ahead=0\n-\t\t\tfor commit in $commits\n-\t\t\tdo\n-\t\t\t\tcase \"$commit\" in\n-\t\t\t\t\"<\"*) ((behind++)) ;;\n-\t\t\t\t*)    ((ahead++))  ;;\n-\t\t\t\tesac\n-\t\t\tdone\n-\t\t\tcount=\"$behind\t$ahead\"\n-\t\telse\n-\t\t\tcount=\"\"\n-\t\tfi\n-\tfi\n-\n-\t# calculate the result\n-\tif [[ -z \"$verbose\" ]]; then\n-\t\tcase \"$count\" in\n-\t\t\"\") # no upstream\n-\t\t\tp=\"\" ;;\n-\t\t\"0\t0\") # equal to upstream\n-\t\t\tp=\"=\" ;;\n-\t\t\"0\t\"*) # ahead of upstream\n-\t\t\tp=\">\" ;;\n-\t\t*\"\t0\") # behind upstream\n-\t\t\tp=\"<\" ;;\n-\t\t*)\t    # diverged from upstream\n-\t\t\tp=\"<>\" ;;\n-\t\tesac\n-\telse\n-\t\tcase \"$count\" in\n-\t\t\"\") # no upstream\n-\t\t\tp=\"\" ;;\n-\t\t\"0\t0\") # equal to upstream\n-\t\t\tp=\" u=\" ;;\n-\t\t\"0\t\"*) # ahead of upstream\n-\t\t\tp=\" u+${count#0\t}\" ;;\n-\t\t*\"\t0\") # behind upstream\n-\t\t\tp=\" u-${count%\t0}\" ;;\n-\t\t*)\t    # diverged from upstream\n-\t\t\tp=\" u+${count#*\t}-${count%\t*}\" ;;\n-\t\tesac\n-\tfi\n-\n-}\n-\n-\n-# __git_ps1 accepts 0 or 1 arguments (i.e., format string)\n-# returns text to add to bash PS1 prompt (includes branch name)\n-__git_ps1 ()\n-{\n-\tlocal g=\"$(__gitdir)\"\n-\tif [ -n \"$g\" ]; then\n-\t\tlocal r=\"\"\n-\t\tlocal b=\"\"\n-\t\tif [ -f \"$g/rebase-merge/interactive\" ]; then\n-\t\t\tr=\"|REBASE-i\"\n-\t\t\tb=\"$(cat \"$g/rebase-merge/head-name\")\"\n-\t\telif [ -d \"$g/rebase-merge\" ]; then\n-\t\t\tr=\"|REBASE-m\"\n-\t\t\tb=\"$(cat \"$g/rebase-merge/head-name\")\"\n-\t\telse\n-\t\t\tif [ -d \"$g/rebase-apply\" ]; then\n-\t\t\t\tif [ -f \"$g/rebase-apply/rebasing\" ]; then\n-\t\t\t\t\tr=\"|REBASE\"\n-\t\t\t\telif [ -f \"$g/rebase-apply/applying\" ]; then\n-\t\t\t\t\tr=\"|AM\"\n-\t\t\t\telse\n-\t\t\t\t\tr=\"|AM/REBASE\"\n-\t\t\t\tfi\n-\t\t\telif [ -f \"$g/MERGE_HEAD\" ]; then\n-\t\t\t\tr=\"|MERGING\"\n-\t\t\telif [ -f \"$g/CHERRY_PICK_HEAD\" ]; then\n-\t\t\t\tr=\"|CHERRY-PICKING\"\n-\t\t\telif [ -f \"$g/BISECT_LOG\" ]; then\n-\t\t\t\tr=\"|BISECTING\"\n-\t\t\tfi\n-\n-\t\t\tb=\"$(git symbolic-ref HEAD 2>/dev/null)\" || {\n-\n-\t\t\t\tb=\"$(\n-\t\t\t\tcase \"${GIT_PS1_DESCRIBE_STYLE-}\" in\n-\t\t\t\t(contains)\n-\t\t\t\t\tgit describe --contains HEAD ;;\n-\t\t\t\t(branch)\n-\t\t\t\t\tgit describe --contains --all HEAD ;;\n-\t\t\t\t(describe)\n-\t\t\t\t\tgit describe HEAD ;;\n-\t\t\t\t(* | default)\n-\t\t\t\t\tgit describe --tags --exact-match HEAD ;;\n-\t\t\t\tesac 2>/dev/null)\" ||\n-\n-\t\t\t\tb=\"$(cut -c1-7 \"$g/HEAD\" 2>/dev/null)...\" ||\n-\t\t\t\tb=\"unknown\"\n-\t\t\t\tb=\"($b)\"\n-\t\t\t}\n-\t\tfi\n-\n-\t\tlocal w=\"\"\n-\t\tlocal i=\"\"\n-\t\tlocal s=\"\"\n-\t\tlocal u=\"\"\n-\t\tlocal c=\"\"\n-\t\tlocal p=\"\"\n-\n-\t\tif [ \"true\" = \"$(git rev-parse --is-inside-git-dir 2>/dev/null)\" ]; then\n-\t\t\tif [ \"true\" = \"$(git rev-parse --is-bare-repository 2>/dev/null)\" ]; then\n-\t\t\t\tc=\"BARE:\"\n-\t\t\telse\n-\t\t\t\tb=\"GIT_DIR!\"\n-\t\t\tfi\n-\t\telif [ \"true\" = \"$(git rev-parse --is-inside-work-tree 2>/dev/null)\" ]; then\n-\t\t\tif [ -n \"${GIT_PS1_SHOWDIRTYSTATE-}\" ]; then\n-\t\t\t\tif [ \"$(git config --bool bash.showDirtyState)\" != \"false\" ]; then\n-\t\t\t\t\tgit diff --no-ext-diff --quiet --exit-code || w=\"*\"\n-\t\t\t\t\tif git rev-parse --quiet --verify HEAD >/dev/null; then\n-\t\t\t\t\t\tgit diff-index --cached --quiet HEAD -- || i=\"+\"\n-\t\t\t\t\telse\n-\t\t\t\t\t\ti=\"#\"\n-\t\t\t\t\tfi\n-\t\t\t\tfi\n-\t\t\tfi\n-\t\t\tif [ -n \"${GIT_PS1_SHOWSTASHSTATE-}\" ]; then\n-\t\t\t\tgit rev-parse --verify refs/stash >/dev/null 2>&1 && s=\"$\"\n-\t\t\tfi\n-\n-\t\t\tif [ -n \"${GIT_PS1_SHOWUNTRACKEDFILES-}\" ]; then\n-\t\t\t\tif [ -n \"$(git ls-files --others --exclude-standard)\" ]; then\n-\t\t\t\t\tu=\"%\"\n-\t\t\t\tfi\n-\t\t\tfi\n-\n-\t\t\tif [ -n \"${GIT_PS1_SHOWUPSTREAM-}\" ]; then\n-\t\t\t\t__git_ps1_show_upstream\n-\t\t\tfi\n-\t\tfi\n-\n-\t\tlocal f=\"$w$i$s$u\"\n-\t\tprintf -- \"${1:- (%s)}\" \"$c${b##refs/heads/}${f:+ $f}$r$p\"\n-\tfi\n-}\ndiff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\nnew file mode 120000\nindex 00000000..a4fbb216\n--- /dev/null\n+++ b/contrib/completion/git-prompt.sh\n@@ -0,0 +1 @@\n+../../git-sh-prompt.sh\n\\ No newline at end of file\ndiff --git a/contrib/completion/git-prompt.sh b/git-sh-prompt.sh\nsimilarity index 100%\nrename from contrib/completion/git-prompt.sh\nrename to git-sh-prompt.sh\n-- \n1.8.0\n"},{"id":"201865","messageId":"5088F402.8090006@mit.edu","threadId":"30595","inReplyTo":"3B606942-D194-4148-AF6E-1F3283C983ED@googlemail.com","subject":"Re: Where should git-prompt.sh be installed?","fromName":"Anders Kaseorg","fromEmail":"andersk@mit.edu","sentAt":"2012-10-25T08:10:42Z","receivedAt":"2012-10-25T08:10:42Z","isPatch":false,"sender":{"key":"andersk@mit.edu","avatar":"https://avatars.githubusercontent.com/u/26471?v=4"},"body":"On 10/25/2012 02:02 AM, Danny Yates wrote:\n> Would that not give the impression of \"git sh-prompt\" being a core\n> command?\n\nNo more than git-sh-setup, which already works like that.  Unless \nperhaps by “core” you mean “not contrib”.\n\n(Now that I think of it, I saw a request from an Ubuntu PPA user last \nweek to install git-subtree in a more accessible location, and there’s a \nsimilar request about gitview at https://bugs.launchpad.net/bugs/152212 \n.  These are less critical since the Debian package puts them in \n/usr/share/doc/git/contrib.  Is it a good idea to package those \nsomewhere like /usr/lib/git-core or /usr/bin, or is that a dangerous \nslippery slope?  I dunno.)\n\nAnders\n"},{"id":"201902","messageId":"CAMP44s02XfVXhJnXqLWwyCE34nW_E-aCx3s=CKc783u7EO2WLg@mail.gmail.com","threadId":"30595","inReplyTo":"20121025074549.GC15790@elie.Belkin","subject":"Re: [RFC/PATCH] __git_ps1: migrate out of contrib/completion","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2012-10-25T14:19:29Z","receivedAt":"2012-10-25T14:19:29Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Thu, Oct 25, 2012 at 9:45 AM, Jonathan Nieder <jrnieder@gmail.com> wrote:\n\n> diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\n> new file mode 120000\n> index 00000000..a4fbb216\n> --- /dev/null\n> +++ b/contrib/completion/git-prompt.sh\n> @@ -0,0 +1 @@\n> +../../git-sh-prompt.sh\n> \\ No newline at end of file\n\n^ no new line?\n\n-- \nFelipe Contreras\n"},{"id":"201903","messageId":"20121025151120.GA14740@goldbirke","threadId":"30595","inReplyTo":"20121025005106.GA9112@elie.Belkin","subject":"Re: Where should git-prompt.sh be installed?","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2012-10-25T15:11:20Z","receivedAt":"2012-10-25T15:11:20Z","isPatch":false,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Wed, Oct 24, 2012 at 05:51:06PM -0700, Jonathan Nieder wrote:\n> Hi,\n> \n> In olden days the admin would copy contrib/completion/git-completion.sh\n> to\n> \n>         /etc/bash_completion.d/git\n> \n> and mortals could source /etc/bash_completion or\n> /etc/bash_completion.d/git in their ~/.bashrc (possibly shared among\n> multiple machines) so that the bash completion and __git_ps1 helpers\n> could work.\n\nAh, the good old days!  I even modified 'make install' to copy the\ncompletion script to /etc/bash_completion.d/.  And I was happy.\n\n> With Git 1.7.12 __git_ps1 has been split into a separate file, to help\n> users who only want __git_ps1 to avoid the overhead of loading the\n> entire completion script (and allow the completion script to be loaded\n> by bash-completion magic on the fly!).  Now the sysadmin should copy\n> contrib/completion/git-completion.sh to\n> \n> \t/usr/share/bash-completion/completions/git\n> \n> and contrib/completion/git-prompt.sh to\n> \n> \t/usr/share/git-core/contrib/?? (somewhere?)\n> \n> Mortals source /etc/bash_completion in their ~/.bashrc (possibly\n> shared among multiple machines) and expect bash completion to work.\n> For __git_ps1, users should source that ?? path.\n> \n> Questions:\n> \n>  1) what path is appropriate for ?? above?\n>  2) is this documented anywhere?\n\nDon't know what is appropriate, and it's not documented.  I for one\ncopy it manually to ~/.git-prompt.sh every once in a while.  And I'm\nnot all that happy with that.\n\n> Possible answers:\n> \n>  1) Fedora uses /etc/profile.d/git-prompt.sh.  Gentoo uses\n>     /usr/share/bash-completion/git-prompt.  Maybe others use\n>     some other path.\n> \n>  2) The scripts themselves suggest copying to ~/.git-completion.sh\n>     and ~/.git-prompt.sh.\n> \n> Proposal:\n> \n>   1) /usr/lib/git-core/git-sh-prompt\n>   2) git-sh-prompt(1)\n\nNot sure about the \"sh\" part.  The prompt function is very\nBash-specific, it won't work under a plain POSIX shell.\n\nDo other VCSes have similar prompt scripts?  Where do they install\ntheirs?\n\n\nGábor\n"},{"id":"201908","messageId":"20121025161250.GA30334@elie.Belkin","threadId":"30595","inReplyTo":"20121025151120.GA14740@goldbirke","subject":"Re: Where should git-prompt.sh be installed?","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2012-10-25T16:12:50Z","receivedAt":"2012-10-25T16:12:50Z","isPatch":false,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"SZEDER Gábor wrote:\n> On Wed, Oct 24, 2012 at 05:51:06PM -0700, Jonathan Nieder wrote:\n\n>> Proposal:\n>>\n>>   1) /usr/lib/git-core/git-sh-prompt\n>>   2) git-sh-prompt(1)\n>\n> Not sure about the \"sh\" part.  The prompt function is very\n> Bash-specific, it won't work under a plain POSIX shell.\n\nThat's an interesting point.  Here's my logic:\n\nThe prompt function was originally Bash-specific, but over time\nit gained support for Zsh as well.  If we're lucky, some day it\nmight gain support for mksh.\n\nMeanwhile something simple like \"git-prompt\" would sound too much\nlike a normal git command, I fear.\n\nShell language extensions used:\n\n * future standard: local variables\n * cosmetic: [[ and (( syntax in place of test and $(\n * cosmetic: for ((n=1; n <= n_stop; n++)) instead of a more explicit\n   while loop\n * cosmetic: var+=value syntax\n * optimization: <<< syntax to iterate over lines in a variable\n   instead of, for example, sed + eval\n * arrays: svn_remote, svn_upstream --- using plain variables would\n   require some escaping.\n\nSo nothing fundamental, but since this is only useful in shells like\nBash that support command substitution in $PS1, it seems reasonable\nto keep using the extensions until someone wants to use it with a\nmore limited shell.\n\nIn other words, the interface is still \"this is a scriptlet you might\nsource in your Bourne-style shell to get a __git_ps1 function to use\nin your prompt\".  The implementation language just happens not to be\nPOSIX shell today.\n\nPerhaps it should return early in shells other than bash and zsh to\nhelp people keep their .shrc simple.  What do you think?\n\n> Do other VCSes have similar prompt scripts?  Where do they install\n> theirs?\n\nMercurial has an hg-prompt extension that can be used by running \"hg\nprompt\".\nhttp://mercurial.selenic.com/wiki/PromptExtension\n\nI haven't found one for Subversion.\n\nBazaar has contrib/bash/bzrbashprompt.sh.  It doesn't get installed.\n\nThanks,\nJonathan\n"},{"id":"202636","messageId":"20121108131910.GE23491@zaya.teonanacatl.net","threadId":"30595","inReplyTo":"20121025074549.GC15790@elie.Belkin","subject":"Re: [RFC/PATCH] __git_ps1: migrate out of contrib/completion","fromName":"Todd Zullinger","fromEmail":"tmz@pobox.com","sentAt":"2012-11-08T13:19:10Z","receivedAt":"2012-11-08T13:19:10Z","isPatch":true,"sender":{"key":"tmz@pobox.com","avatar":"https://avatars.githubusercontent.com/u/806319?v=4"},"body":"Jonathan Nieder wrote:\n> Different installers put the git-prompt.sh shell library at different \n> places on the installed system, so there is no shared location users \n> can count on:\n>\n>  Fedora - /etc/profile.d/git-prompt.sh\n\nFWIW, we moved it to /usr/share/git-core/contrib/completion/ -- it was \nonly ever in /etc/profile.d in an unreleased version of Fedora for a \nshort time.  (Side note: at some point, we'll likely install most or \nall of contrib under /usr/share/git-core/contrib in Fedora.)\n\nHaving it in a more standard location would be excellent, it would \navoid bugs like: https://bugzilla.redhat.com/show_bug.cgi?id=854061 :)\n\n-- \nTodd        OpenPGP -> KeyID: 0xBEAF0CE3 | URL: www.pobox.com/~tmz/pgp\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nOh, very funny!  Now tell the one that doesn't suck.\n       -- Stewie Griffin\n\n"}]}