completion: use __gitcomp_builtin in _git_am
[gitweb.git] / contrib / completion / git-completion.bash
index 8aca836ef9577990c82a1163cfca20a24ee9a0d2..eba482eb9ccbf72eb2aadf9ea6b9d4c1999b7123 100644 (file)
@@ -111,8 +111,7 @@ __git ()
 #   GNU General Public License for more details.
 #
 #   You should have received a copy of the GNU General Public License
-#   along with this program; if not, write to the Free Software Foundation,
-#   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#   along with this program; if not, see <http://www.gnu.org/licenses/>.
 #
 #   The latest version of this software can be obtained here:
 #
@@ -281,6 +280,39 @@ __gitcomp ()
        esac
 }
 
+# This function is equivalent to
+#
+#    __gitcomp "$(git xxx --git-completion-helper) ..."
+#
+# except that the output is cached. Accept 1-3 arguments:
+# 1: the git command to execute, this is also the cache key
+# 2: extra options to be added on top (e.g. negative forms)
+# 3: options to be excluded
+__gitcomp_builtin ()
+{
+       # spaces must be replaced with underscore for multi-word
+       # commands, e.g. "git remote add" becomes remote_add.
+       local cmd="$1"
+       local incl="$2"
+       local excl="$3"
+
+       local var=__gitcomp_builtin_"${cmd/-/_}"
+       local options
+       eval "options=\$$var"
+
+       if [ -z "$options" ]; then
+               # leading and trailing spaces are significant to make
+               # option removal work correctly.
+               options=" $(__git ${cmd/_/ } --git-completion-helper) $incl "
+               for i in $excl; do
+                       options="${options/ $i / }"
+               done
+               eval "$var=\"$options\""
+       fi
+
+       __gitcomp "$options"
+}
+
 # Variation of __gitcomp_nl () that appends to the existing list of
 # completion candidates, COMPREPLY.
 __gitcomp_nl_append ()
@@ -1073,12 +1105,13 @@ __git_count_arguments ()
 }
 
 __git_whitespacelist="nowarn warn error error-all fix"
+__git_am_inprogress_options="--skip --continue --resolved --abort"
 
 _git_am ()
 {
        __git_find_repo_path
        if [ -d "$__git_repo_path"/rebase-apply ]; then
-               __gitcomp "--skip --continue --resolved --abort"
+               __gitcomp "$__git_am_inprogress_options"
                return
        fi
        case "$cur" in
@@ -1087,12 +1120,8 @@ _git_am ()
                return
                ;;
        --*)
-               __gitcomp "
-                       --3way --committer-date-is-author-date --ignore-date
-                       --ignore-whitespace --ignore-space-change
-                       --interactive --keep --no-utf8 --signoff --utf8
-                       --whitespace= --scissors
-                       "
+               __gitcomp_builtin am "--no-utf8" \
+                       "$__git_am_inprogress_options"
                return
        esac
 }
@@ -1121,10 +1150,7 @@ _git_add ()
 {
        case "$cur" in
        --*)
-               __gitcomp "
-                       --interactive --refresh --patch --update --dry-run
-                       --ignore-errors --intent-to-add --force --edit --chmod=
-                       "
+               __gitcomp_builtin add
                return
        esac
 
@@ -1250,7 +1276,8 @@ _git_checkout ()
        --*)
                __gitcomp "
                        --quiet --ours --theirs --track --no-track --merge
-                       --conflict= --orphan --patch
+                       --conflict= --orphan --patch --detach --ignore-skip-worktree-bits
+                       --recurse-submodules --no-recurse-submodules
                        "
                ;;
        *)
@@ -1385,7 +1412,7 @@ _git_describe ()
                __gitcomp "
                        --all --tags --contains --abbrev= --candidates=
                        --exact-match --debug --long --match --always --first-parent
-                       --exclude
+                       --exclude --dirty --broken
                        "
                return
        esac
@@ -1400,7 +1427,7 @@ __git_diff_common_options="--stat --numstat --shortstat --summary
                        --patch-with-stat --name-only --name-status --color
                        --no-color --color-words --no-renames --check
                        --full-index --binary --abbrev --diff-filter=
-                       --find-copies-harder
+                       --find-copies-harder --ignore-cr-at-eol
                        --text --ignore-space-at-eol --ignore-space-change
                        --ignore-all-space --ignore-blank-lines --exit-code
                        --quiet --ext-diff --no-ext-diff
@@ -1922,6 +1949,7 @@ _git_pull ()
        --*)
                __gitcomp "
                        --rebase --no-rebase
+                       --autostash --no-autostash
                        $__git_merge_options
                        $__git_fetch_options
                "
@@ -2336,14 +2364,24 @@ _git_config ()
        esac
        __gitcomp "
                add.ignoreErrors
+               advice.amWorkDir
                advice.commitBeforeMerge
                advice.detachedHead
                advice.implicitIdentity
-               advice.pushNonFastForward
+               advice.pushAlreadyExists
+               advice.pushFetchFirst
+               advice.pushNeedsForce
+               advice.pushNonFFCurrent
+               advice.pushNonFFMatching
+               advice.pushUpdateRejected
                advice.resolveConflict
+               advice.rmHints
                advice.statusHints
+               advice.statusUoption
+               advice.ignoredHook
                alias.
                am.keepcr
+               am.threeWay
                apply.ignorewhitespace
                apply.whitespace
                branch.autosetupmerge
@@ -2406,6 +2444,8 @@ _git_config ()
                core.autocrlf
                core.bare
                core.bigFileThreshold
+               core.checkStat
+               core.commentChar
                core.compression
                core.createObject
                core.deltaBaseCacheLimit
@@ -2415,6 +2455,8 @@ _git_config ()
                core.fileMode
                core.fsyncobjectfiles
                core.gitProxy
+               core.hideDotFiles
+               core.hooksPath
                core.ignoreStat
                core.ignorecase
                core.logAllRefUpdates
@@ -2422,20 +2464,30 @@ _git_config ()
                core.notesRef
                core.packedGitLimit
                core.packedGitWindowSize
+               core.packedRefsTimeout
                core.pager
+               core.precomposeUnicode
                core.preferSymlinkRefs
                core.preloadindex
+               core.protectHFS
+               core.protectNTFS
                core.quotepath
                core.repositoryFormatVersion
                core.safecrlf
                core.sharedRepository
                core.sparseCheckout
+               core.splitIndex
+               core.sshCommand
                core.symlinks
                core.trustctime
                core.untrackedCache
                core.warnAmbiguousRefs
                core.whitespace
                core.worktree
+               credential.helper
+               credential.useHttpPath
+               credential.username
+               credentialCache.ignoreSIGHUP
                diff.autorefreshindex
                diff.external
                diff.ignoreSubmodules
@@ -2467,15 +2519,19 @@ _git_config ()
                format.thread
                format.to
                gc.
+               gc.aggressiveDepth
                gc.aggressiveWindow
                gc.auto
+               gc.autoDetach
                gc.autopacklimit
+               gc.logExpiry
                gc.packrefs
                gc.pruneexpire
                gc.reflogexpire
                gc.reflogexpireunreachable
                gc.rerereresolved
                gc.rerereunresolved
+               gc.worktreePruneExpire
                gitcvs.allbinary
                gitcvs.commitmsgannotation
                gitcvs.dbTableNamePrefix
@@ -2613,7 +2669,10 @@ _git_config ()
                sendemail.suppressfrom
                sendemail.thread
                sendemail.to
+               sendemail.tocmd
                sendemail.validate
+               sendemail.smtpbatchsize
+               sendemail.smtprelogindelay
                showbranch.default
                status.relativePaths
                status.showUntrackedFiles