gitweb.cgi: git_blame2: an alternative simple working git blame
[git/jnareb-git/bp-gitweb.git] / git-reset.sh
blob5c0224090a252bed3258bbbb127e84e61a874197
1 #!/bin/sh
3 USAGE='[--mixed | --soft | --hard] [<commit-ish>]'
4 . git-sh-setup
6 tmp=${GIT_DIR}/reset.$$
7 trap 'rm -f $tmp-*' 0 1 2 3 15
9 update=
10 reset_type=--mixed
11 case "$1" in
12 --mixed | --soft | --hard)
13 reset_type="$1"
14 shift
16 -*)
17 usage ;;
18 esac
20 case $# in
21 0) rev=HEAD ;;
22 1) rev=$(git-rev-parse --verify "$1") || exit ;;
23 *) usage ;;
24 esac
25 rev=$(git-rev-parse --verify $rev^0) || exit
27 # We need to remember the set of paths that _could_ be left
28 # behind before a hard reset, so that we can remove them.
29 if test "$reset_type" = "--hard"
30 then
31 update=-u
34 # Soft reset does not touch the index file nor the working tree
35 # at all, but requires them in a good order. Other resets reset
36 # the index file to the tree object we are switching to.
37 if test "$reset_type" = "--soft"
38 then
39 if test -f "$GIT_DIR/MERGE_HEAD" ||
40 test "" != "$(git-ls-files --unmerged)"
41 then
42 die "Cannot do a soft reset in the middle of a merge."
44 else
45 git-read-tree --reset $update "$rev" || exit
48 # Any resets update HEAD to the head being switched to.
49 if orig=$(git-rev-parse --verify HEAD 2>/dev/null)
50 then
51 echo "$orig" >"$GIT_DIR/ORIG_HEAD"
52 else
53 rm -f "$GIT_DIR/ORIG_HEAD"
55 git-update-ref -m "reset $reset_type $@" HEAD "$rev"
57 case "$reset_type" in
58 --hard )
59 ;; # Nothing else to do
60 --soft )
61 ;; # Nothing else to do
62 --mixed )
63 # Report what has not been updated.
64 git-update-index --refresh
66 esac
68 rm -f "$GIT_DIR/MERGE_HEAD" "$GIT_DIR/rr-cache/MERGE_RR" "$GIT_DIR/SQUASH_MSG"