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