mirror of
https://github.com/zulip/zulip.git
synced 2026-06-24 21:08:25 +08:00
I often find myself looking manually through the reflog of `master` to find a commit I previously reset to with tools/reset-to-pull-request . Sometimes I want to see a previous version of a PR I'm reviewing a revised version of; sometimes to look at two related PRs together. So, here's a feature to automate that by saving each PR branch in its own ref, with a name like `refs/remotes/pr/1234` -- or `pr/1234`, as you'd normally refer to it. To enable this, set the new config option: $ git config zulip.prPseudoRemote pr (Or you can pick another name.) The reason I hesitate to just make this the behavior for everyone immediately is that the resulting `pr/1234` refs will naturally accumulate and may clutter up the view -- and because with the `refs/remotes/` style of name I've chosen, it requires a bit of Git plumbing to clean them up. (Use `git update-ref -d`.) I'll play with it and iterate; comments welcome from other willing early adopters.
28 lines
676 B
Bash
Executable File
28 lines
676 B
Bash
Executable File
#!/bin/bash
|
|
set -e
|
|
|
|
if ! git diff-index --quiet HEAD; then
|
|
set +x
|
|
echo "There are uncommitted changes:"
|
|
git status --short
|
|
echo "Doing nothing to avoid losing your work."
|
|
exit 1
|
|
fi
|
|
|
|
remote_default="$(git config zulip.zulipRemote || echo upstream)"
|
|
pseudo_remote="$(git config zulip.prPseudoRemote || echo)"
|
|
|
|
request_id="$1"
|
|
remote=${2:-"$remote_default"}
|
|
|
|
if [ -z "$pseudo_remote" ]; then
|
|
set -x
|
|
git fetch "$remote" "pull/$request_id/head"
|
|
git reset --hard FETCH_HEAD
|
|
else
|
|
target_ref=refs/remotes/"$pseudo_remote"/"$request_id"
|
|
set -x
|
|
git fetch "$remote" +"pull/$request_id/head":"$target_ref"
|
|
git reset --hard "$target_ref"
|
|
fi
|