-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgit-arc
More file actions
executable file
·65 lines (60 loc) · 1.63 KB
/
git-arc
File metadata and controls
executable file
·65 lines (60 loc) · 1.63 KB
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
#!/bin/bash
# Tool for archiving and restoring git branches.
usage() {
(
echo "usage: ${0##*/} [-h] COMMAND [args]"
echo "Tool for archiving and restoring git branches."
echo "options:"
(
echo " -h: show usage help"
) | column -ts:
echo "commands:"
(
echo " list: list archived branches"
echo " create BRANCH: create an archive ref for the given BRANCH"
echo " delete REF: delete archive for the given REF"
echo " restore REF: restore the branch for the given REF"
) | column -ts:
) >&2
exit 1
}
if echo "$*" | grep -Eq -- '-h\b'; then
usage
fi
# shellcheck source=../.shell_control
# shellcheck disable=SC1091
source "$HOME/.shell_control" || echo "$(tput bold)error: ~/.shell_control not installed!$(tput sgr0)" >&2
case "$1" in
create)
arg="$2"
if [[ -z $arg ]]; then
echo "$(tput bold)error: please provide a branch name to archive$(tput sgr0)" >&2
exit 1
fi
run "git update-ref refs/archive/$arg origin/$arg"
run "git branch -D $arg"
;;
list)
run "git for-each-ref refs/archive"
;;
delete)
arg="$2"
if [[ -z $arg ]]; then
echo "$(tput bold)error: please provide a ref name to delete$(tput sgr0)" >&2
exit 1
fi
run "git update-ref -d $arg"
;;
restore)
arg="$2"
if [[ -z $arg ]]; then
echo "$(tput bold)error: please provide a ref name to restore$(tput sgr0)" >&2
exit 1
fi
run "git branch $(echo "$arg" | cut -c14-) $arg"
run "git update-ref -d $arg"
;;
*)
usage
;;
esac