See only commits from a particular branch - mercurial

So, i made some work on the default branch, then i pushed those changes to my fork and after that i created a pull request from the fork to the parent repo (default branch at fork -> default branch at parent).
After this i created a new branch, made some changes, pushed them and again created a pull request from new branch on fork to new branch on parent.
In this pull request (new branch -> new branch) a see commits that are made in default->default pull request. But i expected to see only commits that i made in the new branch.
So, i want to see commits that i made to default in pull request to default and commits to new branch in the pull request made to this new branch. How do i make it?
I apologize for my awfull english. I tried my best to explain myself.

You can try something like this:
hg log -r 'ancestor(default,pull_request_default)::pull_request_default'
replacing pull_request_default with the last revision of your pull request. It will only show the changesets of the pull request.

Related

TortoiseHG, fork with subrepos - force commit&push .hgsubstate only

There is public repo on mercurial (not mine). It contains two subrepos. I've made a fork for both main repo nad two subrepos. I want to create pull requests from time to time, but I can't make subrepos work properly.
When I clone my forked repo, it will be downloaded, but two subrepos will remain original, not my forked one. If I'll replace them with forked, I won't be able to make a pull request cos I don't want to switch original repo to my subrepos. But I want to change both repo and subrepo.
Once I've found a solution. I've modified hgrc file in .hg folder of subrepo.
It was:
[paths]
default = ssh://hg#bitbucket.org/originator/subrepo
It become:
[paths]
Me = ssh://hg#bitbucket.org/Me/subrepo
Original = ssh://hg#bitbucket.org/originator/subrepo
It was working exactly as it should. I've changed code, pushed to my subrepo, created pull request for subrepo. Then I've pushed changes in my main repo and it simply worked. .hgsubstate is now reffering to commit that exist on forked repo, but not on original one. When orignator will megre both pull requests, everything would work.
Is I said, it worked before, but not now. For some weird reason I can't just push .hgsubstate that point to new subrepo revision that exists on forked subrepo. I simply can't include it in commit. I click "commit", but in result commit it's not included. And I don't know how to force is being included - HG too "smart" about it. Also TortoiseHG marks my subrepo as dirty. But if I'll try to add both .hgsubstate and my dirty repo, it for some reason tries to push changes to originator's repo. It seems like my HG just can't commit .hgsubstate without pushing changes to subrepo on itself.
Any way to solve this? Everything I want is to commit and push .hgsubstate without doing anything else.
Did you adjust your .hgsub accordingly so that it works for both, your local paths as well as the remote paths to which you push to the server?
It's advisable to add to your .hgsub sections which describe the paths in an absolute sense. I used to struggle with that when I had the subrepos as the same level in the dir structure on the server but wanted them as sub-dirs on my own computer. It helped me to add to .hgsub a subpaths section:
[subpaths]
ssh://user#host.org/path/subrepo1 = ssh://user#host.org/subrepo1
ssh://user#host.org/path/subrepo2 = ssh://user#host.org/subrepo2
/home/user/project/subrepo1 = /home/user/subrepo1
/home/user/project/subrepo2 = /home/user/subrepo2
project/subrepo1 = subrepo1
project/subrepo2 = subrepo2

Moving unstaged + uncommitted changes between Mercurial branches

I cloned a Mercurial repo and did a bunch of local work, and forgot to make a feature branch for said work.
The normal flow is:
Clone
Create a branch
Switch to that branch
Do your work in that branch
Push that branch
Code review
If code review passes, merge branch w/ default (locally)
Push merged changes to default
Close the feature branch
So I need to create a new branch, port all my unstaged/uncommitted code changes (made to default) over to this branch (so that default is now clean and the new branch contains my changes), and then push my feature branch.
I created the new branch via hg branch new_feature. But after pouring over the Merucrial docs, I can't figure out the next step.
So I ask: How do I move (not just copy) all my unstaged/uncommitted changes from default to my new_feature branch)?
You shouldn't have to do anything in particular.
Your uncommitted working folder changes are fluid, and you can set the branch name before you commit, without losing your changes.
If you're on the command line, simply do this:
hg branch feature-X
hg commit -m "Added feature X"
If you're using TortoiseHg simply click the "Branch: default" button just above the commit message input field and select "Open a new named branch" and give it a name, then click OK, then commit as normal.
Setting the branch name to use during commit does not in fact change your working folder, it doesn't do an update, it doesn't do anything, except record in metadata what the branch name is supposed to be.
Also note that this will only allow you to create a new branch to commit to. If you want to continue on an existing branch you first need to update to the head of that branch and this may cause changes to your working folder. You should not need to do this, however, if you want to create a new branch.

Mercurial will not let me push. Abort: push creates new remote head

I can't push using mercurial, it states I have to merge. If I do hg merge, will it merge my branch with the main trunk, I really want to avoid that.
I created and modified some files. I did hg add to add them all. I did some commits but it won't let me push them to my branch.
I posted my output of hg commands below:
C:\Users\kacalica\Desktop\Projects\hydroinformatics>hg incoming
comparing with https://stcalica#bitbucket.org/nickrsan/hydroinformatics
searching for changes
no changes found
C:\Users\kacalica\Desktop\Projects\hydroinformatics>hg status
M hydro\forms.py
? graph_test.py
? hydro\mlgraph\__init__.py
? hydro\mlgraph\test.py
? hydro\plugins\__init__.py.orig
? hydro\urls.py.orig
? hydro\views.py.orig
? public\Hydroinformatics\media\test.txt
? public\Hydroinformatics\media\test_EPALM1I.txt
? public\Hydroinformatics\media\test_OIWsXcC.txt
? public\Hydroinformatics\media\test_v5s6RmF.txt
C:\Users\kacalica\Desktop\Projects\hydroinformatics>hg add
adding graph_test.py
adding hydro\mlgraph\__init__.py
adding hydro\mlgraph\test.py
adding hydro\plugins\__init__.py.orig
adding hydro\urls.py.orig
adding hydro\views.py.orig
adding public\Hydroinformatics\media\test.txt
adding public\Hydroinformatics\media\test_EPALM1I.txt
adding public\Hydroinformatics\media\test_OIWsXcC.txt
adding public\Hydroinformatics\media\test_v5s6RmF.txt
C:\Users\kacalica\Desktop\Projects\hydroinformatics>hg push
pushing to https://stcalica#bitbucket.org/nickrsan/hydroinformatics
searching for changes
abort: push creates new remote head b54ae56acf07 on branch 'WITHOUTPLUGINSGRAPHS'!
(merge or see "hg help push" for details about pushing new heads)
C:\Users\kacalica\Desktop\Projects\hydroinformatics>hg commit -m "added files"
abort: last update was interrupted
(use 'hg update' to get a consistent checkout)
C:\Users\kacalica\Desktop\Projects\hydroinformatics>hg update
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
C:\Users\kacalica\Desktop\Projects\hydroinformatics>hg branch
WITHOUTPLUGINSGRAPHS
C:\Users\kacalica\Desktop\Projects\hydroinformatics>hg status
M hydro\forms.py
A graph_test.py
A hydro\mlgraph\__init__.py
A hydro\mlgraph\test.py
A hydro\plugins\__init__.py.orig
A hydro\urls.py.orig
A hydro\views.py.orig
A public\Hydroinformatics\media\test.txt
A public\Hydroinformatics\media\test_EPALM1I.txt
A public\Hydroinformatics\media\test_OIWsXcC.txt
A public\Hydroinformatics\media\test_v5s6RmF.txt
C:\Users\kacalica\Desktop\Projects\hydroinformatics>hg summary
parent: 36:b54ae56acf07 tip
actually added template
branch: WITHOUTPLUGINSGRAPHS
commit: 1 modified, 10 added
update: 10 new changesets, 2 branch heads (merge)
C:\Users\kacalica\Desktop\Projects\hydroinformatics>
OK, first of all, let's sort out our terminology here. In Mercurial, a "head" is a changeset with no child changesets (https://www.mercurial-scm.org/wiki/Head). Let's say you're working in default branch. If you're being told that pushing would create new remote heads, it means there's a different head revision in default on the remote repository (the one you're pushing to). If you pushed, default would have two head revisions!
How does this happen? Well, it might be another developer did a push in the meantime, or you pushed from another repository/computer by mistake. You don't want to push a branch with multiple heads, otherwise you end up with some crazy hydra with loads of heads, none of which has all the code.
First you need to pull from the remote repository. Next, you need to run "hg merge" - if you're using Hg-Workbench or similar, you might not see the other head immediately, so scroll down and find it. If you have conflicts, now's the time to resolve them. Make sure you commit your merge, and then you should be able to push.
If you're on a verison of Mercurial that's not more than a couple year's old do: hg push --new-branch which the hg help push shows lets you push a new branch:
--new-branch allow pushing a new branch
That'll only be necessary the first time you push a new branch -- it's just there to make sure you don't accidentally push something you didn't mean to share.

Bitbucket pull requests automatically merging in code?

I'm just playing around with the bitbucket/mercurial pull requests feature, and either something is behaving strangely, or I'm doing something profoundly stupid.
I (theukdave) am the owner of a repository 'RepoA' which was created under a 'team' (which I gather bitbucket doesn't really have anymore). Let's say this lives at bitbucket.org/team1/RepoA
So I created a fork of that repository under my own username and called it RepoB. So now there's a fork that lives at bitbucket.org/theukdave/RepoB
I then create a test commit on a branch off our main development branch 'develop', and then merged that new branch back into develop. I pushed up to bitbucket.org/theukdave/RepoB, and then created a pull request from 'theukdave/RepoB develop' to 'team1/RepoA develop', I add a title and description and NO reviewers (since I'm just testing right now) and click the 'create pull request' button.
A few moments later, the test commit and merge from RepoB is showing up in my RepoA. The pull request is there, I can see it, I have not yet approved it, but the commit and merge and available to all users of RepoA. Even if I decline the pull request, the test commits are still in RepoA.
Is this because I'm the owner of RepoA, and so my pull requests are automatically merged in? Is it because I added no reviewers? A combo of both? Or am I missing something here ...
First of all really interesting. You can resolve this situation using this steps.
To disable automatic branch merging for all repositories in a project (requires project admin permission):
Go to Project settings > Branching model.
Select Disable automatic merging, then click Save.
I hope useful for you.

Detect creating of branches or bookmarks in HG

Is it possible to detect if a commit creates a new bookmark or branch via hooks in .hgrc?
I've tried to see if I can find out using hg log, but it just shows on what branch/bookmark the commit has been created: http://hgbook.red-bean.com/read/customizing-the-output-of-mercurial.html
There don't seem to be hooks for it: http://hgbook.red-bean.com/read/handling-repository-events-with-hooks.html
It would make sense I suppose that there isn't a hook for it, because it is also not possible to make a commit which is 'just' the creation of the branch indicating branches/bookmarks only exists when added to a specific commit.
I figured I could check hg branches and hg bookmarks before and after each commit and determine which are removed and added, but is there a cleaner way for detecting branch/bookmark adds/removes?
The pushkey and prepushkey hooks can detect the addition, deletion, and moves of bookmarks.
In hgrc:
[hooks]
prepushkey=echo %HG_NAMESPACE% %HG_KEY% %HG_OLD% %HG_NEW%\n >> out.txt
HG_NAMESPACE will contain "bookmark" and HG_KEY will contain the name of the bookmark.
HG_OLD will contain the hash of the commit the bookmark was before the operation. It won't be set if the bookmark is being created.
HG_NEW will contain the hash of the commit the bookmark will be after the operation. It won't be set if the bookmark is being deleted.
Bookmarks
Bookmarks-handling does not require commit
Bookmark can be created|modified for any changeset in history, not only for current
Bookmark(s) can appear as result of data-exchange (pull|push), not local user's actions
Only part of all possible cases can be covered by hook
Branches
Changing branch always reflected in commit
Branch in changeset may differ from parent's branch not only as result of hg branch (see "merge branches" and "mergesets") - and I haven't nice and easy and ready to use solution for this case
Common notes
You can use standard precommit hook (executed before commit and can enable|disable commit) for testing different conditions in commit or or pretxncommit
Mercurial template-engine has keywords for branch and bookmark for using in hg log -T
In pretxncommit hook commit already exist, but not finalized - it means you can manipulate with commit's data using -r tip and tip's parent in any Mercurial command
Dirty skeleton for hook's body
hg log -T "{KEYWORD}\n" -r "tip + tip^" | ....
where KEYWORD may be branch or bookmarks. Result of log is two-strings output, which can be identical of different (not sure for bookmark, TBT!!), which you have to compare (as you want and can)
PS: Idea inspired by EnsureCommitPolicy Wiki and Mercurial pre commit hook topic here