bitbucket mercurial don't show username properly - mercurial

I have my private repository and do commit from my machine. In my hgrc file i have sth like this
[ui]
username = John <jon#mail.com>
In my bucket account I have the same mail and firstname set to John.
Now i do commit and under overview tab I have totally different name. How I can fix it?
Best regards

When you clone from BitBucket it prepends the site with the current logged in username. For example, instead of cloning from https://bitbucket.org/dls/commit-msg-check it will clone from https://dls#bitbucket.org/dls/commit-msg-check. Note the dls# in the second url.
If your local .hgrc or Mercurial.ini files have a different user name in them, BitBucket gets (rightfully) confused. This is how BitBucket shows you that it's confused:
Notice the question marks next to the username. Hovering over them shows "Author not mapped to BitBucket user" help text.
If you're using OpenID to sign into BitBucket, then it would make sense that your username is Artur (the same username that you've used to sign into StackOverflow, I see). In this case, you can check out this link to learn about setting up aliases in BitBucket.

Related

How to set up Mercurial username and email?

I am trying to set up my username and email address on Mercurial. The tutorial says:
Mercurial will need a username to use for recording commits. It's best to configure Mercurial to use your email address by creating a file .hgrc in your home directory (or on Windows in %USERPROFILE%\Mercurial.ini) containing lines like the following:
[ui]
username = John Doe <john#example.com>"
I found the "Mercurial" notepad file in the folder, not an ".ini" and The only thing that is written in that file is "# Generated by TortoiseHg settings dialog"
I did check other related questions and tried to find the answer. But, I really couldn't find. I want to use my bitbucket username and another email address on my commits. I am very new to coding and using version control systems. So, I hope I was able to explain the issue clearly.
Is your Windows set to hide extensions for known file types? That would explain why you don't see .ini in Windows Explorer.
If you open it in Notepad, it should say "mercurial.ini - Notepad" in the title bar of Notepad if it's the correct file.
However, there you can do this through TortoiseHg. Open TortoiseHg Workbench, go to File -> Settings. In the Settings dialog, under the "User's global settings" tab, select "Commit" in the left-hand list, and you'll see User name appear at the top of the pane to the right of the list. Type in your email address there and click OK. That should be it.
(But you could now check the file we discussed earlier and see if it has the relevant bits added to it)

Is there a way to email regular, aggregated mercurial changesets reports?

In an effort to boost code reviews, I am looking to send a daily/weekly/monthly/some_regular_interval report of changes from mercurial? I figure that if a person does not have to go and find the changes, but they are instead brought to the person, then that should be a step in the right direction. However, I did not see anything already out there. (We use mercurial with TortoiseHG and Jenkins for the automated build in case any of those tools might help?)
What I am looking for:
MUST HAVE
commit message
list of files that changed
NICE TO HAVE
changeset guid
name of person who did the commit
some means to see what changed on each file (probably best via a URL or else the email could become overloaded)
You don't state what OS you are using. I am assuming Windows since you are using TortoiseHG.
On Linux (or other UNIX-based OS) you can create a cron that runs once a week/month/whatever. The following simple script satisfies most of your requirements on my Linux machine:
LOG_DATE=`date -d "1 week ago" +"%Y-%m-%d 00:00:00"`
hg log -d ">$LOG_DATE"
If you use Mercurial templates you can get exactly what you want. You can construct a URL using the changeset ID to point to a Mercurial web-server.
Would the notify extension work? You can configure this on a designated master repository so that emails with a summary of the changes (you can customise the template to include the short form of the hash, the user name, the commit message) along with URLs to the individual changesets are sent out to people whenever changese are pushed to the master repository.

Mercurial's authors description

I'm trying to change Mercurial's template.
When I push some files to my repository, the log files list my PC's name, not user's name that is logged in.
I don't want the PC's name, I want logged user's name shows up.
How I do it?
#Praveen-K has the right answer and Lazy Badger and Lasse have the details you're missing. Here it is spelled out, but go pick Praveen's answer:
The user name you're seeing in/on your remote repository are completely unrelated to:
Any settings on your repository/server
The username you use to authenticate to your repository
Instead that string, called 'author' is burned into the changeset (commit) at commit time and is entirely crafted on your "PC". You could set it to anything you want and once you push that commit to the repository that's how it will display.
At your current skill level you're not going to successfully change that string in commits you've already made, but if you dive into a good explanation (not lookup commands) like the hg book you'll come away understanding things.
Make the entry in to your hgrc file. This file should be in your .hg/ directory (it may be in your repo or you can do in your home directory) and if it is not exist make the file with the name of hgrc in that folder.
[ui]
username = Your Name <your#mail>

Change author in mercurial

I have commit my code on bitbucket from another computer and forgot to change the name from default to mine. How can i fix wrong name to mine. Thx in advance.
The issue 3295 addresses your scenario: "Incorrect Author name while Pushing code to BitBucket repository"
The author string is something that comes from the configuration on your machine (since you are committing locally and pushing to Bitbucket).
You can set this string for Hg, this doc talks about doing that.
Similarly you can set the Git author, this doc talks about that.
As for the commits you have already pushed to Bitbucket Sebastian is right that you can just map your committer string to your user by clicking on the '?'.
If you go to the commits screen, you will see a '?', click it, and fill out your BB username on the left side, this will link your BB name to your entered commit name.

Mercurial hook to test that username is valid when pushing to repository

I have a "central" repository that I want to ensure that no one pushes changes in to with a wrong user name.
But I can not figure out how to make a hook that tests the user name against a positive list. I have found in the Mercurial API a ctx.user() call that seems to be what I want to test my positive list against.
Also the hook could be a precommit hook that is distributed as part of the repository clone or it could be a hook on the central repository as a pre-incoming or something like that.
Any help or pointers would be greatly appreciated.
I have posted two functional examples on Bitbucket. Both examples are for searching a commit message for some specifically formatted text (like an issue tracked case ID), but could be easily modified to check a user against a list of valid users.
The first example is actually a Mercurial extension that wraps the 'commit' command. If it fails to find the appropriate text (or valid user in your case), it will prevent the commit from occurring at all. You can enable this in your .hgrc file by adding these lines:
[extensions]
someName = path/to/script/commit-msg-check.py
The second example uses a in-process pretxncommit hook, which runs between when the commit has been made, but before it becomes permanent. If this check fails it will automatically roll back the commit. You can enable this in your .hgrc file by adding these lines (assuming you kept the same file/function names):
[hooks]
pretxncommit.example = python:commit-msg-check-hook.CheckForIssueRecord
You can execute any Python code you like inside of these hooks, so user validation could be done in many ways.
Thanks for the examples dls.
In the end I decided to run it as a pretxnchangegroup hook and then use the hg log and grep to test the author field of the commits:
[hooks]
pretxnchangegroup.usercheck = hg log --template '{author}\n' -r \
$HG_NODE: | grep -qe 'user1\|user2\|etc'
It does of course not provide a very good feedback other than usercheck failed. But I think it is good enough for now.