From: Junio C Hamano Date: Wed, 14 Nov 2007 22:05:47 +0000 (-0800) Subject: Merge branch 'jc/stash-create' X-Git-Tag: v1.5.4-rc0~209 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/5e389c430d232e8b1a16e7357596328985111eab?ds=inline;hp=-c Merge branch 'jc/stash-create' * 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" --- 5e389c430d232e8b1a16e7357596328985111eab diff --combined git-merge.sh index c2092a2040,976117ac90..b9f05192d1 --- a/git-merge.sh +++ b/git-merge.sh @@@ -3,7 -3,7 +3,7 @@@ # Copyright (c) 2005 Junio C Hamano # -USAGE='[-n] [--summary] [--no-commit] [--squash] [-s ] [-m=] +' +USAGE='[-n] [--summary] [--[no-]commit] [--[no-]squash] [--[no-]ff] [-s ] [-m=] +' 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 ;; @@@ -98,19 -96,6 +97,19 @@@ 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 () { @@@ -133,7 -118,11 +132,7 @@@ 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) @@@ -141,17 -130,9 +140,17 @@@ --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) @@@ -184,42 -165,9 +183,42 @@@ 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 5bbda47b7b,696b465b7c..1c8b7f9259 --- a/git-stash.sh +++ b/git-stash.sh @@@ -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) @@@ -84,6 -78,23 +78,23 @@@ 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) || @@@ -162,7 -173,7 +173,7 @@@ 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 ;;