3 # Seek the working tree to a given commit
4 # Copyright (c) Petr Baudis, 2005
6 # Seeking will bring the working tree from its current 'HEAD' to a given
7 # commit. Note that it changes just the 'HEAD' of the working tree, not
8 # the branch it is corresponding to. It will return to the 'HEAD' of
9 # the appropriate branch if passed no arguments.
11 # Therefore, for a quick excursion to the past of the 'master' branch:
13 # $ cg-seek git-pasky-0.1
14 # $ cg-diff this master # will do the correct thing
15 # $ cg-seek # will restore what we had before
17 # For intuitiveness, specifying the branch name (`cg-seek master`) will do
18 # the right thing too. If you want to migrate your working tree to _another_
19 # branch, use `cg-clone` to create a new tree for the new branch, or
20 # `cg-switch` to also change your current tree to use the new branch.
22 # Note that during the time you are seeked out, commits, merges, and some
23 # other operations are blocked, since the next `cg-seek` or `cg-reset`
24 # invocation will happily wipe out their products silently. You can override
25 # this in the `cg-commit` command by passing it a '-f' parameter - this
26 # can be useful e.g. when you seeked to a commit which cannot be compiled
27 # and you want to commit a compilation fix, as long as you are aware that
28 # the commit of the fix will be rendered unreachable (you will be able to
29 # get back to it only if you remember its ID) at the moment you do next
30 # seek or a reset. If you want to save the commit, you can save it to
31 # a separate branch using `cg-switch -n`.
33 # Takes the target commit ID to seek to as an argument.
37 # The `cg-seek` command is meant only for temporary excursions to the commit
38 # history. If you want to permanently switch your branch to a different commit
39 # id (forgetting its current contents), you can use the `cg-switch` command:
41 # $ cg-switch -f -r COMMIT_ID CURRENT_HEAD_NAME
43 # Note that this command has some serious caveats! Please read the
44 # `cg-switch` documentation for details.
46 # Testsuite: Complete (t9300-seek)
48 USAGE
="cg-seek [COMMIT_ID]"
51 .
"${COGITO_LIB}"cg-Xlib ||
exit 1
53 dstcommit
="${ARGS[0]}"
56 [ -s "$_git/blocked" ] && grep -vq '^seeked from ' "$_git/blocked" && die
"action blocked: $(cat "$_git/blocked
")"
58 curcommit
="$(cg-object-id -c)" ||
exit 1
60 if [ "$dstcommit" ] && [ "$dstcommit" != "$_git_head" ]; then
62 [ -s "$_git/head-name" ] && [ "$(git-symbolic-ref HEAD)" != "refs/heads/cg-seek-point" ] &&
63 die
"seeked away by some other tool, refusing to meddle (you can still use cg-seek without any arguments to unseek)"
64 exists_ref
"refs/heads/$dstcommit" ] &&
65 warn
"seeking to a branch head; this is not for permanent switching, please see cg-switch"
68 dstcommit
="$(cg-object-id -c "$_git_head")" ||
exit 1
71 dstcommit
="$(cg-object-id -c "$dstcommit")" ||
exit 1
72 if [ "$curcommit" != "$dstcommit" ]; then
73 tree_timewarp
--no-head-update "along" "please rollback" "$curcommit" "$dstcommit" ||
exit 1
76 if [ "$seek_mode" = "away" ]; then
77 echo "$_git_head" >"$_git/head-name"
78 [ -s "$_git/blocked" ] ||
echo "seeked from $_git_head (some commands can be still forced)" >"$_git/blocked"
79 # We hold this in a temporary branch so that some of the core
80 # GIT tools (git checkout and git-fsck-objects) don't get confused.
81 git-update-ref
"refs/heads/cg-seek-point" "$dstcommit"
82 git-symbolic-ref HEAD
"refs/heads/cg-seek-point"
84 seekpt
="$(get_ref "refs
/heads
/cg-seek-point
")"
85 git-symbolic-ref HEAD
"refs/heads/$_git_head"
86 git-update-ref
-d "refs/heads/cg-seek-point" "$seekpt"
87 rm -f "$_git/head-name"
91 echo "On commit $dstcommit"