Code

Merge branch 'jc/stash-create'
authorJunio C Hamano <gitster@pobox.com>
Wed, 14 Nov 2007 22:05:47 +0000 (14:05 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 14 Nov 2007 22:05:47 +0000 (14:05 -0800)
* jc/stash-create:
  git-stash: Fix listing stashes
  git-merge: no reason to use cpio anymore
  Revert "rebase: allow starting from a dirty tree."
  rebase: allow starting from a dirty tree.
  stash: implement "stash create"

1  2 
git-merge.sh
git-stash.sh

diff --combined git-merge.sh
index c2092a204035ad0315a3d37ed2f70097e68ed052,976117ac9006fcc3bc33b2f6079bd3caad8ed639..b9f05192d1122df13f134b361887060ea042180c
@@@ -3,7 -3,7 +3,7 @@@
  # Copyright (c) 2005 Junio C Hamano
  #
  
 -USAGE='[-n] [--summary] [--no-commit] [--squash] [-s <strategy>] [-m=<merge-message>] <commit>+'
 +USAGE='[-n] [--summary] [--[no-]commit] [--[no-]squash] [--[no-]ff] [-s <strategy>] [-m=<merge-message>] <commit>+'
  
  SUBDIRECTORY_OK=Yes
  . git-sh-setup
@@@ -28,20 -28,19 +28,19 @@@ allow_trivial_merge=
  
  dropsave() {
        rm -f -- "$GIT_DIR/MERGE_HEAD" "$GIT_DIR/MERGE_MSG" \
-                "$GIT_DIR/MERGE_SAVE" || exit 1
+                "$GIT_DIR/MERGE_STASH" || exit 1
  }
  
  savestate() {
        # Stash away any local modifications.
-       git diff-index -z --name-only $head |
-       cpio -0 -o >"$GIT_DIR/MERGE_SAVE"
+       git stash create >"$GIT_DIR/MERGE_STASH"
  }
  
  restorestate() {
-         if test -f "$GIT_DIR/MERGE_SAVE"
+         if test -f "$GIT_DIR/MERGE_STASH"
        then
                git reset --hard $head >/dev/null
-               cpio -iuv <"$GIT_DIR/MERGE_SAVE"
+               git stash apply $(cat "$GIT_DIR/MERGE_STASH")
                git update-index --refresh >/dev/null
        fi
  }
@@@ -59,7 -58,7 +58,7 @@@ finish_up_to_date () 
  squash_message () {
        echo Squashed commit of the following:
        echo
 -      git log --no-merges ^"$head" $remote
 +      git log --no-merges ^"$head" $remoteheads
  }
  
  finish () {
@@@ -82,7 -81,6 +81,7 @@@
                        ;;
                *)
                        git update-ref -m "$rlogm" HEAD "$1" "$head" || exit 1
 +                      git gc --auto
                        ;;
                esac
                ;;
                fi
                ;;
        esac
 +
 +      # Run a post-merge hook
 +        if test -x "$GIT_DIR"/hooks/post-merge
 +        then
 +          case "$squash" in
 +          t)
 +                "$GIT_DIR"/hooks/post-merge 1
 +              ;;
 +          '')
 +                "$GIT_DIR"/hooks/post-merge 0
 +              ;;
 +          esac
 +        fi
  }
  
  merge_name () {
        fi
  }
  
 -case "$#" in 0) usage ;; esac
 -
 -have_message=
 -while case "$#" in 0) break ;; esac
 -do
 +parse_option () {
        case "$1" in
        -n|--n|--no|--no-|--no-s|--no-su|--no-sum|--no-summ|\
                --no-summa|--no-summar|--no-summary)
        --summary)
                show_diffstat=t ;;
        --sq|--squ|--squa|--squas|--squash)
 -              squash=t no_commit=t ;;
 +              allow_fast_forward=t squash=t no_commit=t ;;
 +      --no-sq|--no-squ|--no-squa|--no-squas|--no-squash)
 +              allow_fast_forward=t squash= no_commit= ;;
 +      --c|--co|--com|--comm|--commi|--commit)
 +              allow_fast_forward=t squash= no_commit= ;;
        --no-c|--no-co|--no-com|--no-comm|--no-commi|--no-commit)
 -              no_commit=t ;;
 +              allow_fast_forward=t squash= no_commit=t ;;
 +      --ff)
 +              allow_fast_forward=t squash= no_commit= ;;
 +      --no-ff)
 +              allow_fast_forward=false squash= no_commit= ;;
        -s=*|--s=*|--st=*|--str=*|--stra=*|--strat=*|--strate=*|\
                --strateg=*|--strategy=*|\
        -s|--s|--st|--str|--stra|--strat|--strate|--strateg|--strategy)
                have_message=t
                ;;
        -*)     usage ;;
 -      *)      break ;;
 +      *)      return 1 ;;
        esac
        shift
 +      args_left=$#
 +}
 +
 +parse_config () {
 +      while test $# -gt 0
 +      do
 +              parse_option "$@" || usage
 +              while test $args_left -lt $#
 +              do
 +                      shift
 +              done
 +      done
 +}
 +
 +test $# != 0 || usage
 +
 +have_message=
 +
 +if branch=$(git-symbolic-ref -q HEAD)
 +then
 +      mergeopts=$(git config "branch.${branch#refs/heads/}.mergeoptions")
 +      if test -n "$mergeopts"
 +      then
 +              parse_config $mergeopts
 +      fi
 +fi
 +
 +while parse_option "$@"
 +do
 +      while test $args_left -lt $#
 +      do
 +              shift
 +      done
  done
  
  if test -z "$show_diffstat"; then
@@@ -437,7 -385,7 +436,7 @@@ case "$use_strategies" i
      single_strategy=no
      ;;
  *)
-     rm -f "$GIT_DIR/MERGE_SAVE"
+     rm -f "$GIT_DIR/MERGE_STASH"
      single_strategy=yes
      ;;
  esac
@@@ -495,13 -443,7 +494,13 @@@ don
  # auto resolved the merge cleanly.
  if test '' != "$result_tree"
  then
 -    parents=$(git show-branch --independent "$head" "$@" | sed -e 's/^/-p /')
 +    if test "$allow_fast_forward" = "t"
 +    then
 +        parents=$(git show-branch --independent "$head" "$@")
 +    else
 +        parents=$(git rev-parse "$head" "$@")
 +    fi
 +    parents=$(echo "$parents" | sed -e 's/^/-p /')
      result_commit=$(printf '%s\n' "$merge_msg" | git commit-tree $result_tree $parents) || exit
      finish "$result_commit" "Merge made by $wt_strategy."
      dropsave
diff --combined git-stash.sh
index 5bbda47b7b6e286e7e8e5d002d7ed461a831b579,696b465b7c7853f717dca6b2c865647161df25d9..1c8b7f92591f87b2d32b51cca6173921c5e041b2
@@@ -21,23 -21,17 +21,17 @@@ no_changes () 
  clear_stash () {
        if current=$(git rev-parse --verify $ref_stash 2>/dev/null)
        then
-               git update-ref -d refs/stash $current
+               git update-ref -d $ref_stash $current
        fi
  }
  
save_stash () {
create_stash () {
        stash_msg="$1"
  
        if no_changes
        then
-               echo >&2 'No local changes to save'
                exit 0
        fi
-       test -f "$GIT_DIR/logs/$ref_stash" ||
-               clear_stash || die "Cannot initialize stash"
-       # Make sure the reflog for stash is kept.
-       : >>"$GIT_DIR/logs/$ref_stash"
  
        # state of the base commit
        if b_commit=$(git rev-parse --verify HEAD)
        w_commit=$(printf '%s\n' "$stash_msg" |
                git commit-tree $w_tree -p $b_commit -p $i_commit) ||
                die "Cannot record working tree state"
+ }
+ save_stash () {
+       stash_msg="$1"
+       if no_changes
+       then
+               echo >&2 'No local changes to save'
+               exit 0
+       fi
+       test -f "$GIT_DIR/logs/$ref_stash" ||
+               clear_stash || die "Cannot initialize stash"
+       create_stash "$stash_msg"
+       # Make sure the reflog for stash is kept.
+       : >>"$GIT_DIR/logs/$ref_stash"
  
        git update-ref -m "$stash_msg" $ref_stash $w_commit ||
                die "Cannot save the current status"
@@@ -139,7 -150,7 +150,7 @@@ apply_stash () 
        unstashed_index_tree=
        if test -n "$unstash_index" && test "$b_tree" != "$i_tree"
        then
 -              git diff --binary $s^2^..$s^2 | git apply --cached
 +              git diff-tree --binary $s^2^..$s^2 | git apply --cached
                test $? -ne 0 &&
                        die 'Conflicts in index. Try without --index.'
                unstashed_index_tree=$(git-write-tree) ||
                        git read-tree "$unstashed_index_tree"
                else
                        a="$TMP-added" &&
 -                      git diff --cached --name-only --diff-filter=A $c_tree >"$a" &&
 +                      git diff-index --cached --name-only --diff-filter=A $c_tree >"$a" &&
                        git read-tree --reset $c_tree &&
                        git update-index --add --stdin <"$a" ||
                                die "Cannot unstage modified files"
@@@ -202,6 -213,13 +213,13 @@@ apply
  clear)
        clear_stash
        ;;
+ create)
+       if test $# -gt 0 && test "$1" = create
+       then
+               shift
+       fi
+       create_stash "$*" && echo "$w_commit"
+       ;;
  help | usage)
        usage
        ;;