Skip to content

Instantly share code, notes, and snippets.

@akheron
Created October 31, 2011 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akheron/1327465 to your computer and use it in GitHub Desktop.
Save akheron/1327465 to your computer and use it in GitHub Desktop.
Git aliases and hooks for CPython workflow
# Aliases for working with a hg-git enabled mercurial repository in .git/hg
[alias]
hg-dir = "!echo ${GIT_DIR:-.git}/hg"
hg-run = "!hg -R $(git hg-dir)"
hg-git-dir = "!echo $(git hg-dir)/.hg/git"
hg-git-branch = "!f() { [ \"$1\" = default ] && echo master || echo \"$1\"; }; f"
hg-update-bookmarks = "!git hg-run branches | while read branch rev rest; do target=$(git hg-git-branch $branch); rev=$(echo $rev | sed -r \"s/([0-9]+):.*/\\1/\"); git hg-run bookmark -f -r $rev $target; done"
hg-delete-bookmarks = "!git hg-run bookmarks | sed -r 's/[[:space:]]+(.+?)[[:space:]]+.*/\\1/' | xargs -n 1 git hg-run bookmark -d"
hg-hg2git = "!git hg-update-bookmarks && git hg-run gexport"
hg-git2hg = "!git hg-delete-bookmarks && git hg-run gimport"
hg-fetch = "!git hg-run pull && git hg-hg2git"
hg-outgoing = "!git hg-git2hg && git hg-run outgoing"
hg-push = "!git hg-git2hg && git hg-run push"
#!/bin/sh
# Check whether we already have hg-git metadata
grep -r -e "^--HG--$" $1 && grep -r -e "^branch : " $1 && exit 0
branch=$(git symbolic-ref HEAD 2>/dev/null | sed s:refs/heads/::)
if [ -n "$branch" -a "$branch" != "master" ]; then
printf '\n\n--HG--\nbranch : %s\n' "$branch" > $1.tmp
cat $1 >> $1.tmp
mv $1.tmp $1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment