[PATCH] record: checks for valid username before starting the recording process

Idan Kamara idankk86 at gmail.com
Tue Aug 28 02:09:24 CDT 2012


On Tue, Aug 28, 2012 at 1:04 AM, Sumeet <sumeet at fb.com> wrote:
>
> # HG changeset patch
> # User Sumeet <sumeet at fb.com>
> # Date 1346096470 25200
> # Node ID 8d5630194133943d546ee71b2d8486d37a697719
> # Parent  c6f88e7f95b764e23b7e0b4353c5a6458bbc3cc4
> record: checks for valid username before starting the recording process

When fixing a bug we include the bug id in the first line of the
commit message so the bot can pick it up and update the
bug tracker automatically. So in this case it will be:

record: check for valid username before starting the recording process
(issue3456)

>
> It is quite a bad UX when you spend some time selecting changes for
> recording and at the end everything is lost,
> because username is not configured for this clone.
> 'hg record' used to record all the changes and then check for username
> before commiting the changes.
> Bug in upstream mercurial: http://bz.selenic.com/show_bug.cgi?id=3456
>
> This patch now will help check record for valid username before recording
> changes.
> I added a test case in test-record.t which unsets username and tries to
> record changes to a file which terminates with error code 255.

<nitpick>I'd drop the last paragraph from the commit message as it doesn't
add much info.</nitpick>

>
> diff --git a/hgext/record.py b/hgext/record.py
> --- a/hgext/record.py
> +++ b/hgext/record.py
> @@ -496,6 +496,10 @@
>          raise util.Abort(_('running non-interactively, use %s instead') %
>                           cmdsuggest)
>
> +    # Bug 3456
> +    if not ui.username():
> +        raise util.Abort(_('no username supplied'))
> +

Looking at the implementation of ui.username(), it
already raises an exception:

http://selenic.com/repo/hg/file/99a2a4ae35e2/mercurial/ui.py#l418

So simply doing:

# make sure username is set before going interactive
ui.username()

should suffice.

>      def recordfunc(ui, repo, message, match, opts):
>          """This is generic record driver.
>
> diff --git a/tests/test-record.t b/tests/test-record.t
> --- a/tests/test-record.t
> +++ b/tests/test-record.t
> @@ -246,10 +246,24 @@
>    +9
>    +10
>
> +Modify end of plain file with username unset
> +
> +  $ unset HGUSER
> +  $ unset EMAIL
> +  $ unset LOGNAME
> +  $ echo 11 >> plain
> +  $ hg record -d '8 0' -m end plain <<EOF
> +  > y
> +  > y
> +  > EOF
> +  abort: no username supplied (see "hg help config")
> +  [255]
> +

And you can see that here, because the message is different
than yours ;)

By the way, the easier way to test this would probably be:

$ hg record --config ui.username= -d '8 0' -m end plain

(I dropped the heredoc on purpose because including it
kind of defeats the purpose of the test :)

>
>  Modify end of plain file
>
> -  $ echo 11 >> plain
> +  $ HGUSER="test"
> +  $ export HGUSER
>    $ hg record -d '8 0' -m end plain <<EOF
>    > y
>    > y
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20120828/bca01e5a/attachment.html>


More information about the Mercurial-devel mailing list