]> git.ipfire.org Git - thirdparty/git.git/blame - git-reset.sh
Trace into a file or an open fd and refactor tracing code.
[thirdparty/git.git] / git-reset.sh
CommitLineData
40d8cfe4 1#!/bin/sh
45d197a4 2
806f36d4
FK
3USAGE='[--mixed | --soft | --hard] [<commit-ish>]'
4. git-sh-setup
2f9d685c 5
c68998f5 6update=
45d197a4
JH
7reset_type=--mixed
8case "$1" in
9--mixed | --soft | --hard)
10 reset_type="$1"
11 shift
12 ;;
2f9d685c
CS
13-*)
14 usage ;;
45d197a4
JH
15esac
16
ac83aa2e
JH
17case $# in
180) rev=HEAD ;;
191) rev=$(git-rev-parse --verify "$1") || exit ;;
20*) usage ;;
21esac
2ad77e67 22rev=$(git-rev-parse --verify $rev^0) || exit
45d197a4
JH
23
24# We need to remember the set of paths that _could_ be left
25# behind before a hard reset, so that we can remove them.
26if test "$reset_type" = "--hard"
27then
c68998f5 28 update=-u
45d197a4
JH
29fi
30
31# Soft reset does not touch the index file nor the working tree
32# at all, but requires them in a good order. Other resets reset
33# the index file to the tree object we are switching to.
34if test "$reset_type" = "--soft"
35then
36 if test -f "$GIT_DIR/MERGE_HEAD" ||
37 test "" != "$(git-ls-files --unmerged)"
32173e69 38 then
45d197a4 39 die "Cannot do a soft reset in the middle of a merge."
32173e69 40 fi
45d197a4 41else
c68998f5 42 git-read-tree --reset $update "$rev" || exit
45d197a4
JH
43fi
44
45# Any resets update HEAD to the head being switched to.
46if orig=$(git-rev-parse --verify HEAD 2>/dev/null)
47then
48 echo "$orig" >"$GIT_DIR/ORIG_HEAD"
49else
50 rm -f "$GIT_DIR/ORIG_HEAD"
51fi
dee4e384
JH
52git-update-ref -m "reset $reset_type $*" HEAD "$rev"
53update_ref_status=$?
45d197a4
JH
54
55case "$reset_type" in
56--hard )
c68998f5 57 ;; # Nothing else to do
45d197a4
JH
58--soft )
59 ;; # Nothing else to do
60--mixed )
61 # Report what has not been updated.
215a7ad1 62 git-update-index --refresh
45d197a4
JH
63 ;;
64esac
65
7d0c6887 66rm -f "$GIT_DIR/MERGE_HEAD" "$GIT_DIR/rr-cache/MERGE_RR" "$GIT_DIR/SQUASH_MSG"
dee4e384
JH
67
68exit $update_ref_status