forked from mozilla/moz-git-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-to-hg-commit
executable file
·41 lines (33 loc) · 1.11 KB
/
git-to-hg-commit
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
#!/bin/bash
set -e
hg_repo=$1
git_commit_id=$2
if [[ "$git_commit_id" == "" ]]; then
git_commit_id="HEAD"
fi
if [[ "$git_commit_id" == "" || "$hg_repo" == "" ]]; then
echo "Usage: $(basename $0) path-to-hg-repo [path-to-git-repo] [git-commit-id]" 1>&2
exit 255
fi
function git_log()
{
# $1: The format to pass to git log.
git log -n1 "$git_commit_id" --pretty="format:$1"
}
# If git doesn't have an e-mail address, it substitutes "<none@none>", which will mess us up.
commit_user=$(git_log '%an <%ae>' | sed -e 's/ <none@none>//')
commit_date=$(git_log '%aD')
search_str=$(git_log ' %B' | head -n1)
# Locate the hg {desc}|{node} pair containing the commit message from search_str.
hg_str=$(hg log -R "$hg_repo" --user "$commit_user" --date "$commit_date" --template '{node} {desc|firstline}\n' | grep -F "$search_str") || true
if [[ "$hg_str" == "" ]]; then
echo "No matching commit found." 1>&2
exit 1
elif (( "$(echo "$hg_str" | wc -l)" > 1 )); then
echo "Uh oh; multiple matching commits!" 1>&2
echo "$hg_str" 1>&2
exit 2
fi
# Cool; we found it!
hg_node=$(echo "$hg_str" | cut -f 1 -d ' ')
echo "$hg_node"