I have a clone of a repository with one head, nice and simple. After pulling in someone else's changes, I have a script that counts the heads to see if a merge is required. But if the other person has made a branch and merged it, "hg heads" shows two heads, and the script thinks it has to merge. What should the test really be?
Before:
0 - 1
After:
0 - 1 - 2 - 3
\ /
4 (branch)
This doesn't need merging. But a simple comparison of the number of heads before and after would suggest that it does. Why does Mercurial even show more than one head in this case?
The merge process is simple. Usually you will want to merge the tip into your working directory. Thus you run hg merge and Mercurial will incorporate the changes from the tip into your local changes; Tip will then become the second parent revision of your working directory.
To start a merge between the two heads, we use the hg merge command. We resolve the contents of hello. c This updates the working directory so that it contains changes from both heads, which is reflected in both the output of hg parents and the contents of hello.
Description. Update the repository's working directory to the specified changeset. If no changeset is specified, update to the tip of the current named branch and move the active bookmark (see hg help bookmarks). Update sets the working directory's parent revision to the specified changeset (see hg help parents).
Instead of calling hg heads
call hg heads --topo
which shows only topological heads -- those with no kids. You're see the head of their merged branch, but since it was merged in it's not a topological head and --topo
will suppress it.
If you don't have spaces in your branch names, then you can use this script:
#!/bin/sh
for b in $(hg branches -q); do
h=$(hg heads --template "." $b)
if test ${#h} -gt 1; then
echo "Branch $b needs merging, it has ${#h} heads"
fi
done
It iterates over each open branch and counts the number of heads on it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With