Merge branch 'sg/stash-k-i'
authorJunio C Hamano <gitster@pobox.com>
Sun, 13 Jul 2008 22:15:27 +0000 (15:15 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sun, 13 Jul 2008 22:15:27 +0000 (15:15 -0700)
* sg/stash-k-i:
Documentation: tweak use case in "git stash save --keep-index"
stash: introduce 'stash save --keep-index' option

1  2 
Documentation/git-stash.txt
contrib/completion/git-completion.bash
index 9b6b9110911df997c7595a2698fed08c9902cf9f,e2c87223769a47a271d91720887197765bccbacd..e42c5eff4dbc579edc6f65107ecef54fe942847d
@@@ -36,12 -36,15 +36,15 @@@ is also possible)
  OPTIONS
  -------
  
- save [<message>]::
+ save [--keep-index] [<message>]::
  
        Save your local modifications to a new 'stash', and run `git reset
        --hard` to revert them.  This is the default action when no
        subcommand is given. The <message> part is optional and gives
        the description along with the stashed state.
+ +
+ If the `--keep-index` option is used, all changes already added to the
+ index are left intact.
  
  list [<options>]::
  
@@@ -56,7 -59,7 +59,7 @@@ stash@{0}: WIP on submit: 6ebd0e2... Up
  stash@{1}: On master: 9cc0589... Add git-stash
  ----------------------------------------------------------------
  +
 -The command takes options applicable to the `git-log`
 +The command takes options applicable to the 'git-log'
  command to control what is shown and how. See linkgit:git-log[1].
  
  show [<stash>]::
@@@ -64,7 -67,7 +67,7 @@@
        Show the changes recorded in the stash as a diff between the
        stashed state and its original parent. When no `<stash>` is given,
        shows the latest one. By default, the command shows the diffstat, but
 -      it will accept any format known to `git-diff` (e.g., `git stash show
 +      it will accept any format known to 'git-diff' (e.g., `git stash show
        -p stash@\{1}` to view the second most recent stash in patch form).
  
  apply [--index] [<stash>]::
@@@ -158,7 -161,7 +161,7 @@@ $ git reset --soft HEAD
  ... continue hacking ...
  ----------------------------------------------------------------
  +
 -You can use `git-stash` to simplify the above, like this:
 +You can use 'git-stash' to simplify the above, like this:
  +
  ----------------------------------------------------------------
  ... hack hack hack ...
@@@ -169,6 -172,24 +172,24 @@@ $ git stash appl
  ... continue hacking ...
  ----------------------------------------------------------------
  
+ Testing partial commits::
+ You can use `git stash save --keep-index` when you want to make two or
+ more commits out of the changes in the work tree, and you want to test
+ each change before committing:
+ +
+ ----------------------------------------------------------------
+ ... hack hack hack ...
+ $ git add --patch foo            # add just first part to the index
+ $ git stash save --keep-index    # save all other changes to the stash
+ $ edit/build/test first part
+ $ git commit foo -m 'First part' # commit fully tested change
+ $ git stash pop                  # prepare to work on all other changes
+ ... repeat above five steps until one commit remains ...
+ $ edit/build/test remaining parts
+ $ git commit foo -m 'Remaining parts'
+ ----------------------------------------------------------------
  SEE ALSO
  --------
  linkgit:git-checkout[1],
index 27332ed8b1266604594d74b63d806bbaf98f8a88,595de80ea4263a07a88fcdc30887e45c6dac60f0..84a256ec54875288ff0c92e4ce1cc45551667aeb
@@@ -451,18 -451,6 +451,18 @@@ __git_find_subcommand (
        done
  }
  
 +__git_has_doubledash ()
 +{
 +      local c=1
 +      while [ $c -lt $COMP_CWORD ]; do
 +              if [ "--" = "${COMP_WORDS[c]}" ]; then
 +                      return 0
 +              fi
 +              c=$((++c))
 +      done
 +      return 1
 +}
 +
  __git_whitespacelist="nowarn warn error error-all strip"
  
  _git_am ()
@@@ -509,8 -497,6 +509,8 @@@ _git_apply (
  
  _git_add ()
  {
 +      __git_has_doubledash && return
 +
        local cur="${COMP_WORDS[COMP_CWORD]}"
        case "$cur" in
        --*)
  
  _git_bisect ()
  {
 -      local subcommands="start bad good reset visualize replay log"
 +      __git_has_doubledash && return
 +
 +      local subcommands="start bad good skip reset visualize replay log run"
        local subcommand="$(__git_find_subcommand "$subcommands")"
        if [ -z "$subcommand" ]; then
                __gitcomp "$subcommands"
        fi
  
        case "$subcommand" in
 -      bad|good|reset)
 +      bad|good|reset|skip)
                __gitcomp "$(__git_refs)"
                ;;
        *)
@@@ -562,7 -546,7 +562,7 @@@ _git_branch (
        --*)
                __gitcomp "
                        --color --no-color --verbose --abbrev= --no-abbrev
 -                      --track --no-track
 +                      --track --no-track --contains --merged --no-merged
                        "
                ;;
        *)
@@@ -629,8 -613,6 +629,8 @@@ _git_cherry_pick (
  
  _git_commit ()
  {
 +      __git_has_doubledash && return
 +
        local cur="${COMP_WORDS[COMP_CWORD]}"
        case "$cur" in
        --*)
@@@ -650,8 -632,6 +650,8 @@@ _git_describe (
  
  _git_diff ()
  {
 +      __git_has_doubledash && return
 +
        local cur="${COMP_WORDS[COMP_CWORD]}"
        case "$cur" in
        --*)
@@@ -754,8 -734,6 +754,8 @@@ _git_ls_tree (
  
  _git_log ()
  {
 +      __git_has_doubledash && return
 +
        local cur="${COMP_WORDS[COMP_CWORD]}"
        case "$cur" in
        --pretty=*)
@@@ -1108,8 -1086,6 +1108,8 @@@ _git_remote (
  
  _git_reset ()
  {
 +      __git_has_doubledash && return
 +
        local cur="${COMP_WORDS[COMP_CWORD]}"
        case "$cur" in
        --*)
  
  _git_shortlog ()
  {
 +      __git_has_doubledash && return
 +
        local cur="${COMP_WORDS[COMP_CWORD]}"
        case "$cur" in
        --*)
@@@ -1163,15 -1137,24 +1163,26 @@@ _git_show (
  _git_stash ()
  {
        local subcommands='save list show apply clear drop pop create'
-       if [ -z "$(__git_find_subcommand "$subcommands")" ]; then
+       local subcommand="$(__git_find_subcommand "$subcommands")"
+       if [ -z "$subcommand" ]; then
                __gitcomp "$subcommands"
+       else
+               local cur="${COMP_WORDS[COMP_CWORD]}"
+               case "$subcommand,$cur" in
+               save,--*)
+                       __gitcomp "--keep-index"
+                       ;;
+               *)
+                       COMPREPLY=()
+                       ;;
+               esac
        fi
  }
  
  _git_submodule ()
  {
 +      __git_has_doubledash && return
 +
        local subcommands="add status init update"
        if [ -z "$(__git_find_subcommand "$subcommands")" ]; then
                local cur="${COMP_WORDS[COMP_CWORD]}"
@@@ -1378,8 -1361,6 +1389,8 @@@ _git (
  
  _gitk ()
  {
 +      __git_has_doubledash && return
 +
        local cur="${COMP_WORDS[COMP_CWORD]}"
        local g="$(git rev-parse --git-dir 2>/dev/null)"
        local merge=""