]>
Commit | Line | Data |
---|---|---|
40d8cfe4 | 1 | #!/bin/sh |
2ce633b9 JH |
2 | # |
3 | # Copyright (c) 2005, 2006 Linus Torvalds and Junio C Hamano | |
4 | # | |
5 | USAGE='[--mixed | --soft | --hard] [<commit-ish>] [ [--] <paths>...]' | |
a81c311f | 6 | SUBDIRECTORY_OK=Yes |
806f36d4 | 7 | . git-sh-setup |
2f9d685c | 8 | |
2ce633b9 JH |
9 | update= reset_type=--mixed |
10 | unset rev | |
11 | ||
12 | while case $# in 0) break ;; esac | |
13 | do | |
14 | case "$1" in | |
15 | --mixed | --soft | --hard) | |
16 | reset_type="$1" | |
17 | ;; | |
18 | --) | |
19 | break | |
20 | ;; | |
21 | -*) | |
22 | usage | |
23 | ;; | |
24 | *) | |
25 | rev=$(git-rev-parse --verify "$1") || exit | |
26 | shift | |
27 | break | |
28 | ;; | |
29 | esac | |
30 | shift | |
31 | done | |
32 | ||
33 | : ${rev=HEAD} | |
34 | rev=$(git-rev-parse --verify $rev^0) || exit | |
35 | ||
36 | # Skip -- in "git reset HEAD -- foo" and "git reset -- foo". | |
37 | case "$1" in --) shift ;; esac | |
38 | ||
39 | # git reset --mixed tree [--] paths... can be used to | |
40 | # load chosen paths from the tree into the index without | |
41 | # affecting the working tree nor HEAD. | |
42 | if test $# != 0 | |
43 | then | |
44 | test "$reset_type" == "--mixed" || | |
45 | die "Cannot do partial $reset_type reset." | |
46 | git ls-tree -r --full-name $rev -- "$@" | | |
47 | git update-index --add --index-info || exit | |
48 | git update-index --refresh | |
49 | exit | |
50 | fi | |
51 | ||
a81c311f JH |
52 | TOP=$(git-rev-parse --show-cdup) |
53 | if test ! -z "$TOP" | |
54 | then | |
55 | cd "$TOP" | |
56 | fi | |
57 | ||
45d197a4 JH |
58 | if test "$reset_type" = "--hard" |
59 | then | |
c68998f5 | 60 | update=-u |
45d197a4 JH |
61 | fi |
62 | ||
63 | # Soft reset does not touch the index file nor the working tree | |
64 | # at all, but requires them in a good order. Other resets reset | |
65 | # the index file to the tree object we are switching to. | |
66 | if test "$reset_type" = "--soft" | |
67 | then | |
68 | if test -f "$GIT_DIR/MERGE_HEAD" || | |
69 | test "" != "$(git-ls-files --unmerged)" | |
32173e69 | 70 | then |
45d197a4 | 71 | die "Cannot do a soft reset in the middle of a merge." |
32173e69 | 72 | fi |
45d197a4 | 73 | else |
c68998f5 | 74 | git-read-tree --reset $update "$rev" || exit |
45d197a4 JH |
75 | fi |
76 | ||
77 | # Any resets update HEAD to the head being switched to. | |
78 | if orig=$(git-rev-parse --verify HEAD 2>/dev/null) | |
79 | then | |
80 | echo "$orig" >"$GIT_DIR/ORIG_HEAD" | |
81 | else | |
82 | rm -f "$GIT_DIR/ORIG_HEAD" | |
83 | fi | |
dee4e384 JH |
84 | git-update-ref -m "reset $reset_type $*" HEAD "$rev" |
85 | update_ref_status=$? | |
45d197a4 JH |
86 | |
87 | case "$reset_type" in | |
88 | --hard ) | |
95f2fb7d JS |
89 | test $update_ref_status = 0 && { |
90 | echo -n "HEAD is now at " | |
91 | GIT_PAGER= git log --max-count=1 --pretty=oneline \ | |
92 | --abbrev-commit HEAD | |
93 | } | |
94 | ;; | |
45d197a4 JH |
95 | --soft ) |
96 | ;; # Nothing else to do | |
97 | --mixed ) | |
98 | # Report what has not been updated. | |
215a7ad1 | 99 | git-update-index --refresh |
45d197a4 JH |
100 | ;; |
101 | esac | |
102 | ||
49ed2bc4 JH |
103 | rm -f "$GIT_DIR/MERGE_HEAD" "$GIT_DIR/rr-cache/MERGE_RR" \ |
104 | "$GIT_DIR/SQUASH_MSG" "$GIT_DIR/MERGE_MSG" | |
dee4e384 JH |
105 | |
106 | exit $update_ref_status |