Can "secret" be set to the default phase of mercurial? - mercurial

I would like to create "secret" commit instead of "draft" commit by default in a mercurial project. Is there any way to configure mercurial so that the default phase is "secret" instead of "draft" ?

From hg help phases
To make yours commits secret by default, put this in your configuration
file:
[phases]
new-commit = secret

Related

In Ansible, how to make an Mercurial task detect a change just when there are new changesets in the repository?

In Ansible, when I have a mercurial task to get some code from a repository, the notification is always triggered:
- name: Deploy code from BitBucket
hg: repo=https://bitbucket.org/user/repo
dest=/home/user/code
purge=yes
notify:
- restart server
Is it possible to prevent triggering it when there are no new changesets in the repository?
It, probably, is not doing that because you set purge=yes.
Looking in the hg module source, we can see that a change notification will be triggered when there's a changeset or the repository was cleaned:
#line 268
if before != after or cleaned:
changed = True
To the hg module, a cleaned repository is a repository that was purged or force updated(force=yes):
#line 256
cleaned = hg.cleanup(force, purge)
So you just need to remove the purge=yes and, maybe, get rid of the untracked files by yourself.

mercurial changegroup hook - specify most recent node

I want to use mercurial hooks to trigger regression builds (in Jenkins) when developers push from their local repos to a central, remote repo.
In path/to/repo/.hg/hgrc
[hooks]
changegroup = python:jenkins.py:trigger_build
And jenkins.py:
def trigger_build(ui, repo, source, hooktype, node, **Kwargs):
...
changeset_to_build = node
...
But in this case, node refers to the earliest changeset in the changegroup, I want to kick off building and testing against the most recent. I have a workaround that uses:
def trigger_build(ui, repo, source, hooktype, node, **Kwargs):
...
changeset_to_build = repo['default'].hex()
...
This gets the appropriate changeset, but I'm not sure it's the best way of doing this. Is there a more standard idiom that I'm missing?
Thanks
it seems to me that repo['default'] is always the head of the default branch. that could be a problem if developers expect builds for other branches or the default branch is not named default.
in a hook based on bash and revsets, i'd use the following:
#!/bin/bash
changeset_to_build=$(hg log --rev "heads(${HG_NODE}:)" --limit 1 --template "{node}")
that would be the first node without child changeset between HG_NODE and tip; so even if the changegroup does not start in the default branch, it is the head of the changegroup that jenkins should build.

Temporarily disable a hook?

Is it possible to temporarily disable a hook when running a mercurial command? e.g., something like:
hg push --no-hook
According to this bugfeature, the following skips local hooks:
hg --config alias._pull=pull _pull
Obviously this is a hack, but it has worked since 2011, and is the only way to skip local hooks given the lack of a '--no-hooks' option.
You can't disable a remote repository's hook. But you could enable or disable a local hook via --config option:
$ hg commit -m test --config 'hooks.commit.info=set | grep "^HG_"'
If this is an outgoing or preoutgoing hook that is locally configured, you can disable it by commenting out its entry under [hooks] in .hg/hgrc. If this is a hook configured on the repository that you are pushing to (changegroup, incoming, prechangegroup, pretxnchangegroup), you will have to comment out its entry under [hooks] in the target repository's .hg/hgrc (if you have access to it).

In Mercurial, after "hg init" to create a project and pushing onto server, how to make local directory to have "hg path" of the server?

When a project is started with
mkdir proj
cd proj
hg init
[create some files]
hg add file.txt
hg commit
hg push ssh://me#somewhere.somehost.com/proj
now when hg path is issued, nothing will show. How do we actually change the repository so that it is as if it is cloned from me#somewhere.somehost.com/proj ? Is it just by editing .hg/hgrc and adding
[paths]
default = ssh://me#somewhere.somehost.com/proj
because that feels like too low level an operation to do (by editing a text file)
It's the only way to do it in this situation. There are plenty of other cases where you have to edit the hgrc by hand, like setting up hooks or enabling extensions, so it's not as if it's unusual.
(As you probably already know, hg clone will set the path entry in the clone to point back to the original.)

How to pull in upstream changes into a fork using Mercurial?

I've forked a Mercurial repository, and now I want to pull the changes from the main repository into my fork. If this were git, I would do something like...
git remote add upstream <url>
git pull upstream master
How do I do this sort of thing in Mercurial?
You could also modify your hgrc file in your repo
default = ssh://hg#bitbucket.org/<my_user>/<my_repo>
upstream = ssh://hg#bitbucket.org/<other_user>/<other_repo>
Then you can do
hg pull upstream
If you cloned the repository from the one you want to pull changes from, you can simply do:
hg pull
If you cloned the repository from another repository, you can:
hg pull <location of repository to pull from>
You'll then need to update your working copy:
hg update
That's the basics, anyway. More details are available in the Mercurial: The Definitive Guide
Have you tried the pull command?
hg pull http://master.com/master
If that does not work, please elaborate.
You could also modify your hgrc file in your repo to use the special path names default and default-push.
default-push = ssh://hg#bitbucket.org/<my_user>/<my_repo>
default = ssh://hg#bitbucket.org/<other_user>/<other_repo>
Then you can pull from upstream (aka default) with
hg pull
and push to fork (aka default-push) with
hg push