-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathgit-pullpr
More file actions
executable file
·89 lines (74 loc) · 2.87 KB
/
git-pullpr
File metadata and controls
executable file
·89 lines (74 loc) · 2.87 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash
set -euo pipefail
if [[ -n "${GIT_PILE_VERBOSE:-}" ]]; then
set -x
fi
if [[ $# -lt 1 ]]; then
echo "usage: $0 <sha_to_update>" >&2
exit 1
fi
export GIT_SEQUENCE_EDITOR=true
# determine branch name
# fetch it
# pull it
# take commit(s)? that aren't part of the given sha and --fixup them
# rebase -i to autosquash them
readonly commit_to_update=$1
if ! git cat-file -e "$commit_to_update" 2> /dev/null; then
echo "error: invalid commit sha: '$commit_to_update'" >&2
exit 1
fi
branch_name="${GIT_PILE_PREFIX:-}$(git show --no-patch --format=%f "$commit_to_update" | tr '[:upper:]' '[:lower:]')"
if ! git show-ref --quiet "$branch_name"; then
echo "error: branch '$branch_name' doesn't exist" >&2
exit 1
fi
worktree_name=$(git roothash)
readonly worktree_dir="$HOME/.cache/git-pile/$worktree_name"
if [[ ! -d "$worktree_dir" ]]; then
git worktree add -f "$worktree_dir" "$branch_name"
else
git -C "$worktree_dir" switch "$branch_name"
fi
_detach_branch() {
git -C "$worktree_dir" switch --detach --quiet
}
trap _detach_branch EXIT
git -C "$worktree_dir" pull --quiet
# branch_with_remote=$(git -C "$worktree_dir" rev-parse --abbrev-ref --symbolic-full-name "@{upstream}")
# remote_name="${branch_with_remote%%/*}"
# remote_branch_name="${branch_with_remote#*/}"
# git -C "$worktree_dir" fetch "$remote_name" "$remote_branch_name"
# if ! git -C "$worktree_dir" diff --quiet "HEAD...@{upstream}"; then
# git -C "$worktree_dir" diff "HEAD...@{upstream}"
# answer=$(_ask "warning: upstream has new commits, would you like to pull those (or abort)? (y/n) ")
# if [[ "$answer" == y ]]; then
# git -C "$worktree_dir" pull
# else
# echo "warning: not updating PR, checkout '$branch_name', pull and try again" >&2
# exit 1
# fi
# fi
# if ! git -C "$worktree_dir" cherry-pick "$new_refspec^..$base_refspec"; then
# # TODO if you exit in vim with :cq, it asks you if it was successful, i think if you hit yes it will continue even if it's not?
# if git -C "$worktree_dir" mergetool; then
# git -C "$worktree_dir" cherry-pick --continue
# else
# git -C "$worktree_dir" cherry-pick --abort
# # TODO what do i do? i think we have to reset branch state? maybe just abort cherry pick?
# exit 1
# fi
# fi
# if [[ "$squash" == true ]]; then
# if [[ "$signoff" == true ]]; then
# git -C "$worktree_dir" commit -s --amend --fixup=HEAD~
# else
# git -C "$worktree_dir" commit --amend --fixup=HEAD~
# fi
# git -C "$worktree_dir" rebase --interactive --autosquash HEAD~2
# git -C "$worktree_dir" push --force-with-lease --quiet || echo "warning: failed to force push '$branch_name'" >&2
# else
# git -C "$worktree_dir" push --quiet || echo "warning: failed to push '$branch_name'" >&2
# fi
# git rebase --interactive --exec "git commit --amend --fixup '$commit_to_update'" "$new_refspec"^
# git rebase --interactive --autosquash "$commit_to_update"^