Test commit
[cogito/jonas.git] / cg-reset
blob3be7de99bea1bf8f52b13b682685948801764a4b
1 #!/usr/bin/env bash
3 # Reset the state of the working tree
4 # Copyright (c) Petr Baudis, 2005
6 # Reverts the working tree to a consistent state before any changes to it
7 # (including merges etc.) were done. This command will rebuild the state
8 # of the tree according to the latest commit on your current branch, so if
9 # your working tree got into basically any inconsistent state, this will
10 # cure it.
12 # Basically, this is the opposite of `cg-commit` in some sense.
14 # This command is complementary to `cg-restore`, which only brings
15 # individual files in sync with their state at the time of the
16 # last commit.
18 # OPTIONS
19 # -------
20 # --adds-removes:: Only reset info about added and removed files
21 # Reset ONLY the so-called "index" file. This effectively means that
22 # any adds and removes you did will be unrecorded (but if you removed
23 # the file physically as well, that will not be undone - run
24 # 'cg-restore' to restore it physically afterwards).
26 # Testsuite: TODO
28 USAGE="cg-reset [--adds-removes]"
29 _git_requires_root=1
31 . "${COGITO_LIB}"cg-Xlib || exit 1
34 indexonly=
35 while optparse; do
36 if optparse --adds-removes; then
37 indexonly=1
38 else
39 optfail
41 done
43 [ "${ARGS[0]}" ] && die "this command takes no parameters; use cg-restore to restore individual files"
46 if [ "$indexonly" ]; then
47 ( git-read-tree --reset HEAD ) && git-update-index --refresh
48 exit
52 if ! [ -s "$_git/HEAD" ]; then
53 rm -f "$_git/HEAD"
54 # XXX: git-symbolic-ref is a weenie and won't do the job at this point.
55 echo "ref: refs/heads/$_git_head" >"$_git/HEAD"
58 # Undo seek?
59 if [ -s "$_git/head-name" ]; then
60 seekpt="$(get_ref "refs/heads/cg-seek-point")"
61 echo "Unseeking: $(get_ref "$(git-symbolic-ref HEAD)") -> $(get_ref "refs/heads/$_git_head") ($_git_head)"
62 if exists_ref "refs/heads/$_git_head"; then
63 git-symbolic-ref HEAD "refs/heads/$_git_head"
64 git-update-ref -d "refs/heads/cg-seek-point" "$seekpt"
65 rm "$_git/head-name"
66 else
67 echo "ERROR: Unknown branch $_git_head! Cancelling unseek." >&2
71 rm -f "$_git/blocked"
72 rm -rf "$_git/cg-merge-state"
73 # Moved to cg-merge-state as of 2006-11-17
74 rm -f "$_git/merging" "$_git/merging-sym" "$_git/merge-base" "$_git/commit-ignore" "$_git/squashing"
75 git-read-tree --reset HEAD
77 git-checkout-index -u -f -a