Last active
December 17, 2015 18:29
-
-
Save ytomino/5653703 to your computer and use it in GitHub Desktop.
git stashを改造してみた。 (1). HEADとindexとworking treeが全部異なるファイルがあるときにgit stash -k && git stash popってやると、何もしてないのにconflictしやがる問題のfix。 (2). メッセージを指定しなかった時のデフォルトメッセージに現在の日付を追加。 (3). git stash listに-v(--verbose)オプションを追加。ハッシュ値を見ることができる。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- Homebrew/Cellar/git/1.8.2/libexec/git-core/git-stash.orig 2013-03-23 06:07:23.000000000 +0900 | |
+++ bin/git-mystash 2013-05-27 14:40:09.000000000 +0900 | |
@@ -34,9 +34,17 @@ | |
fi | |
no_changes () { | |
- git diff-index --quiet --cached HEAD --ignore-submodules -- && | |
- git diff-files --quiet --ignore-submodules && | |
- (test -z "$untracked" || test -z "$(untracked_files)") | |
+ keep_index="$1" # 引数追加 | |
+ if test "$keep_index" = "t" | |
+ then | |
+ # $keep_index時はindexが変更されていても気にしない | |
+ git diff-files --quiet --ignore-submodules && | |
+ (test -z "$untracked" || test -z "$(untracked_files)") | |
+ else | |
+ git diff-index --quiet --cached HEAD --ignore-submodules -- && | |
+ git diff-files --quiet --ignore-submodules && | |
+ (test -z "$untracked" || test -z "$(untracked_files)") | |
+ fi | |
} | |
untracked_files () { | |
@@ -59,9 +67,10 @@ | |
create_stash () { | |
stash_msg="$1" | |
untracked="$2" | |
+ keep_index="$3" # 引数追加 | |
git update-index -q --refresh | |
- if no_changes | |
+ if no_changes "$keep_index" # 引数追加 | |
then | |
exit 0 | |
fi | |
@@ -82,6 +91,16 @@ | |
fi | |
msg=$(printf '%s: %s' "$branch" "$head") | |
+ # keep_index時は現在のindexからコミットを作ってそれを親にする | |
+ if test "$keep_index" = "t" | |
+ then | |
+ # make temporary commit | |
+ i_tree=$(git write-tree) && | |
+ b_commit=$(printf 'base index on %s\n' "$msg" | | |
+ git commit-tree $i_tree -p $b_commit) || | |
+ die "$(gettext "Cannot save the current index state")" | |
+ fi | |
+ | |
# state of the index | |
i_tree=$(git write-tree) && | |
i_commit=$(printf 'index on %s\n' "$msg" | | |
@@ -148,6 +167,9 @@ | |
if test -z "$stash_msg" | |
then | |
stash_msg=$(printf 'WIP on %s' "$msg") | |
+ # 日付も付けとけ | |
+ NOW=$(date -j '+%Y-%m-%d %H:%M:%S %z') | |
+ stash_msg="$stash_msg at $NOW" | |
else | |
stash_msg=$(printf 'On %s: %s' "$branch" "$stash_msg") | |
fi | |
@@ -218,7 +240,7 @@ | |
stash_msg="$*" | |
git update-index -q --refresh | |
- if no_changes | |
+ if no_changes "$keep_index" # 引数追加 | |
then | |
say "$(gettext "No local changes to save")" | |
exit 0 | |
@@ -226,7 +248,7 @@ | |
test -f "$GIT_DIR/logs/$ref_stash" || | |
clear_stash || die "$(gettext "Cannot initialize stash")" | |
- create_stash "$stash_msg" $untracked | |
+ create_stash "$stash_msg" "$untracked" "$keep_index" # 引数追加 | |
# Make sure the reflog for stash is kept. | |
: >>"$GIT_DIR/logs/$ref_stash" | |
@@ -265,7 +287,33 @@ | |
list_stash () { | |
have_stash || return 0 | |
- git log --format="%gd: %gs" -g "$@" $ref_stash -- | |
+ | |
+ # 引数パース | |
+ verbose= | |
+ while test $# != 0 | |
+ do | |
+ case "$1" in | |
+ -v|--verbose) | |
+ verbose=t | |
+ ;; | |
+ --) | |
+ shift | |
+ break | |
+ ;; | |
+ *) | |
+ break | |
+ ;; | |
+ esac | |
+ shift | |
+ done | |
+ | |
+ # -v(--verbose)が指定されていたらreflogを見せる | |
+ if test "$verbose" = "t" | |
+ then | |
+ git reflog show stash | |
+ else | |
+ git log --format="%gd: %gs" -g "$@" $ref_stash -- | |
+ fi | |
} | |
show_stash () { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment