[PATCH] Add git-save script

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When my boss has something to show me and I have to update, for some reason I
am always in the middle of doing something else, and git pull command refuses
to work in such a case.

I wrote this little script to save the changes I made, perform the update,
and then come back to where I was, but on top of the updated commit.

Here is how to use my script:

    $ git save
    $ git pull
    $ git save restore

Signed-off-by: Nanako Shiraishi <nanako3@xxxxxxxxxxxxxx>

diff --git a/git-save.sh b/git-save.sh
new file mode 100755
index 0000000..b45652e
--- /dev/null
+++ b/git-save.sh
@@ -0,0 +1,74 @@
+#! /bin/sh
+
+. git-sh-setup
+require_work_tree
+
+function save_work () {
+	save=$( (
+		i_tree=$(git-write-tree)
+
+		TMP=$GIT_DIR/.git-save-tmp
+		GIT_INDEX_FILE=$TMP
+		export GIT_INDEX_FILE
+
+		git-read-tree $i_tree
+		git-add -u
+		w_tree=$(git-write-tree)
+		rm $TMP
+		git-read-tree --prefix=base/ HEAD^{tree}
+		git-read-tree --prefix=indx/ $i_tree
+		git-read-tree --prefix=work/ $w_tree
+		git-write-tree
+		rm $TMP
+	) )
+
+	head=$(git-log --abbrev-commit --pretty=oneline -n 1 HEAD)
+	if branch=$(git symbolic-ref -q HEAD); then
+		branch=${branch#refs/heads/}
+	else
+		branch='(no branch)'
+	fi &&
+	msg=$(printf 'WIP on %s "%s"' "$branch" "$head")
+
+	saved=$(printf '%s' "$msg" | git-commit-tree "$save")
+	git update-ref -m "$msg" refs/heads/saved $saved
+	printf 'Saved %s\n' "$msg" >&2
+}
+
+function list_save () {
+	git-log --abbrev-commit --pretty=oneline -g "$@" saved
+}
+
+function show_save () {
+	save=$(git rev-parse --verify --default saved "$1")
+	git diff-tree --stat $save:base $save:work
+}
+
+function restore_save () {
+	save=$(git rev-parse --verify --default saved "$1")
+	h_tree=$(git rev-parse --verify $save:base)
+	i_tree=$(git rev-parse --verify $save:indx)
+	w_tree=$(git rev-parse --verify $save:work)
+
+	git-merge-recursive $h_tree -- HEAD^{tree} $w_tree
+}
+
+if [ "$1" = list ]; then
+	shift
+	if [ "$#" = 0 ]; then
+		set x -n 10
+		shift
+	fi
+	list_save "$@"
+elif [ "$1" = show ]; then
+	shift
+	show_save "$@"
+elif [ "$1" = restore ]; then
+	shift
+	restore_save "$@"
+else
+	save_work
+	git reset --hard
+fi
+
+
-- 
しらいし ななこ http://ivory.ap.teacup.com/nanako3/

----------------------------------------------------------------------
Get a free email address with REAL anti-spam protection.
http://www.bluebottle.com

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux