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