-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathgit-legacy
executable file
·69 lines (57 loc) · 1.62 KB
/
git-legacy
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
#!/usr/bin/env bash
app_name="$(basename "${BASH_SOURCE[0]}")"
app_dir="$(dirname "${BASH_SOURCE[0]}")"
print_help() {
expand -t 4 << EOF
Usage:
$app_name <revision>
Rebase the whole history of current HEAD on top of <revision>.
$app_name
Continue rebase loop after an interrupt.
Options:
-?, --help
Show this help information and exit.
EOF
}
args=()
while [[ $# -gt 0 ]]; do
case "$1" in
-\?|--help)
print_help
exit 0
;;
-*)
echo "$app_name: [Error] Unknown option: $1" >&2
exit 1
;;
*)
args+=("$1")
shift
;;
esac
done
set -- "${args[@]}"
git_dir="$(git rev-parse --git-dir)" || exit $?
interrupt () {
echo "Interrupted."
exit 1
}
trap interrupt INT
rebase_loop () {
while [[ -d "$git_dir/rebase-merge" ]]; do
git add . && git -c core.editor=true rebase --continue
done
}
if [[ $# -eq 0 ]]; then
rebase_loop
elif [[ $# -eq 1 ]]; then
if ! "${app_dir}/git-is-worktree-clean" -q; then
echo "$app_name: [Error] Working tree has changes." >&2 &&
return 1
fi
history_tip="$1"
git -c rebase.instructionFormat='%s%nexec git clean -fd; comm -13 -z <(git ls-tree --name-only -r %H -z | sort -z) <(git ls-files -z | sort -z) | xargs -0 rm -rf; git checkout --quiet %H -- . && git add . && GIT_AUTHOR_DATE="%ai" GIT_AUTHOR_NAME="%an" GIT_AUTHOR_EMAIL="%ae" GIT_COMMITTER_DATE="%ci" GIT_COMMITTER_NAME="%cn" GIT_COMMITTER_EMAIL="%ce" git commit --quiet --amend --no-edit' rebase -i --rebase-merges --update-refs "$history_tip"
rebase_loop
else
echo "$app_name: [Error] Invalid number of arguments ($#): Pass a git revision name to start rebase or nothing to continue automatic merge loop." >&2
fi