TortoiseHg Apply a Patch - mercurial

TortoiseHg allows you to email a patch file of your changes to someone, but does it support applying patches?
If so, how do you apply a patch using TortoiseHg?

From Repository Explorer, Repository > Import...

It looks like there is no built-in support in TortoiseHg for this. Try this from a command prompt:
hg import my-patch-file.patch
That should apply the patch to your Mercurial repo and working copy.
First Stab Answer
You should be able to right-click on the patch file and choose "Apply patch..." - that's how it works for other TortoiseX clients. Make sure that you save the patch file to the same directory path it was generated from.
Downloading TortoiseHg 0.8.1 to test...

What may be also noteworthy is, that "Repository Explorer, Synchronize > Import..." (which internally does a "hg import") will automatically do a "commit" - this may not be always wanted behaviour.
Other possibility is to use unix "patch" command (on Windows perhaps use cygwin version) or use "hg import" directly with "--no-commit" option. Both will just make changes in working directory and you may review the changes and commit them later manually.

In 1.0, from Workbench:
Repository > Import...

Related

What does it mean that hg applies a patch to a working directory?

I am trying to use patches (to revive a corrupted repository) for the first time in my life. So I am not very well familiar with the concept, though I've read a bit. I am using TortoiseHg. I have created a patch (as a file), switched to another repository, and am trying to import it. I've asked THg to import it to Repository (other options are Shelf and Working Directory). When I click Import, THg says that the patch was imported to a working directory and the Console reads:
% hg import --verbose --"PATH\1059.patch"
applying PATH\1059.patch
applied to working directory
[command completed successfully DATE]
and I don't see any changes in the history window (no revision 1059). I wonder what I should do now or what I am doing wrong.
I am on Windows 10, TortoiseHg 4.9 with Mercurial 4.9.
When something is modified in your working directory by any means, it does not automatically affect anything in your repository. You have to manually commit such a change.
For the command line hg patch I think the default is to commit automatically. It may be that THG is using the --no-commit option. You could inspect this in the THG output / log window.
For the command line, there is also this note in the help import ...
first applies changes to the working directory (unless --bypass is
specified), import will abort if there are outstanding changes.
The THG Import window looks like this:
According to the docs
You have the choice of importing directly into the repository, the
working folder, a shelf file, or your patch queue.
I think if you inspect the "patches will be imported to" dropdown, it may be set to "working directory" or similar. If you change it to "Repository" I think it will commit for you.
Unless a better answer is provided, I have to assume that this behaviour is due to the corrupted repository: it is not observed when doing exactly the same with a non-corrupted repository.

How to get meld to use hgignore

I've just started using Meld. I'm using its Version Control Diff feature and its working well, except that it doesn't seem to use the .hgignore file.
The tree I'm working in is huge, but I only mercurial-track a small portion, so Meld is taking a loong time to scan the entire tree, 90% of which I could care less about.
I'm using Meld 1.6.0, which doesn't appear to allow the user to manually select the VC type, so I'm forced to start the compare in the directory containing the .hg sub-dir.
Is there a way to get Meld to use the .hgignore file or perhaps override Meld's default VC choice?
I think you should do "the other way around", that is:
configure mercurial to use meld as its "external diff" tool, utilizing "extdiff" extension.
NOTE: All of the above has been tested in UNIX-like environment
in ~/.hgrc enable "extdiff" extension by adding to [extensions] section:
[extensions]
extdiff =
add this below:
[extdiff]
cmd.meld = # if meld is not in your path, you may need to type in here the absolute path to the script
Save ~/.hgrc file.
Now, Then a new hg subcommand shall be available to you.
Enter the hg repo folder, in terminal:
user#machine:~$ cd myrepo
user#machine:~/myrepo$ hg meld
That would spawn meld properly, respectful to .hgignore, mercurial respects itself )
For GUI trickery, you may hook this up to context menus of your favourite file manager:
1. Linux: you may to dance with the Shaman's drum a bit more, but TortoiseHg respects extdiff extension.
1. Windows: TortoiseHg does this automagically
1. Mac: no idea how to do this to Finder :), maybe AppleScripting will be needed here.
Regards.

When using Mercurial HG, how to just get the latest code?

I am new to Mercurial HG. My friends created a repo and I am going to use it.
I installed TortoiseHG and trying to get the latest code. I found that when using Clone operation, it will pull all code to my local, including the histories (Am I right?). This is not needed for me. I just wanna get the latest code. Is there an operation for this?
In short, no.
In a bit longer: Mercurial doesn't yet support “shallow” clones where you only get part of the history. So each time you clone you pull in the entire repository with all changesets.
Additionally, unlike Subversion, there is no way to make a “narrow” clone where you only checkout a portion of a repository. For example, if a repository has directories foo/ and bar/, there is no way to get only the bar/ directory. In other words, Mercurial always operates on project-wide snapshots.
The easiest way to achieve what you want:
hg archive [destination folder]
Once you cloned a repository, to get the code of the "tip" (the last version of the current branch - the default one if not precised) you just need to update.
You have an update action in TortoiseHG. Once done, you can look at the files in the folder.
If you wanted another state of the repository (an old version, or an old tagged state) then it's still the update command, with other parametters (see the docs or the TortoiseHG interface).
If you only want the latest code, and you don't intend to do anything related to the repository with it, like commit, or diff to older versions, or whatever, then you it depends on where you got the code from and how.
If he is using one of the hosting services, like bitbucket, there's usually a download link which gives you just the source code.
For instance, if you go here, there's a "Get source" link up and to the right which gives you a few choices in the file format (zip or whatnot.)
If you got the files somewhere else, you need to explore the interface you got them from. Try just pasting the link you cloned from into your browser and see what you get.
Sure. Clone the repository, then delete the .hg subdirectory.
I might be a bit late but actually it is possible to forget some history with Mercurial. You just need to enable convert extension from Your mercurial.ini file or .hgrc file.
[extensions]
hgext.convert=
Now you are able to use convert extension to "clone" only changesets starting from the revision specified.
hg convert --config convert.hg.startrev=[wheretostart] path_to_full_history_repo path_to_new_repo
Just note that this is not the same operation with hg clone. That's why the source repository must be a local repository. For example if we have a repository in folder MyProject and we want to forget all the changes done before revision 100. We can use the following command:
hg convert --config convert.hg.startrev=[100] MyProject MyShrinkedProject
If You are going to use this shrunken repository on a "central server" remember to take care of that everybody clones it before they continue working. Repositories are not compatible with each other anymore.
Mercurial now supports shallow clone using remotefilelog extension. Extension is bundled with mercurial probably since version 4.9. Older versions need to download the extension e.g. from github.
You have to enable it on the server e.g:
[extensions]
remotefilelog =
[remotefilelog]
server = True
serverexpiration = 14
and on client
[extensions]
remotefilelog =
[remotefilelog]
cachepath = /some/path
cachelimit = 5 GB
Than you can do shallow clone with much smaller footprint a and faster clone speed:
hg clone --shallow ssh://user#server/repo

Is it possible to use the Mercurial Fetch extension with the TortoiseHg merge dialog?

I'm trying to implement Mercurial in the company where I work. Previously we used ClearCase, but for various reasons we decided to upgrade to Mercurial. The development team is very accustomed to the ClearCase workflow, especially the visual tools. Therefore, for our implementation of Mercurial, we will be using TortoiseHg.
A Mercurial extension that caught my attention is the Fetch extension, which allows to do a "hg pull -u" followed by "hg merge" and "hg commit", if necessary. The extension basically does what we want and integrates perfectly with TortoiseHg configuring it to run automatically "Post Pull."
The only problem is that the Fetch extension does not allow to compile and test the merge before running the commit. However, using the TortoiseHg merge dialog with "hgtk merge -r tip" there is a visual way to run the merge command, but with the advantage of allowing me to compile and run the tests. If all went well I press the Commit button, but if something went wrong just press Undo and everything is back as before.
TortoiseHg Merge Dialog: http://www.freeimagehosting.net/uploads/a2f43fe5ff.png
So, my question is:
Is it possible to use the Mercurial Fetch extension with the TortoiseHg merge dialog?
If it's not possible, how would you recommend implementing this workflow? Is there a way to assign an Alias to this secuence:
hg pull -u
* if merge is needed *
hgtk merge -r tip
I am not sure if you could have an "if" in an alias, but I think not.
To answer your last question: no, there are no way to make such aliases with the command line version of Mercurial or with TortoiseHg.

Mercurial: No editor appears when merge conflicts are detected

I wonder if anyone here has any experience with mercurial running on Ubuntu? I've been playing with it all morning and love everything I've seen so far.
The one problem I though is when I do a merge and conflicts are detected, it doesn't automatically bring the file up in the command line editor to allow me to resolve the conflicts. It just tells me there's a conflict, then it's up to me to open the editor and resolve it.
But this is strange as the docs show that the editor is automatically launched when there is a merge conflict. I know it's not a problem with the editor (nano) in general as it's works when I do a commit and have to add a comment.
Any ideas?
Chris
p.s I already tried the mercurial IRC channel, but silence....
You probably need to define your merge tool in ~/.hgrc:
[ui]
merge = vimdiff
What commands are you using, and what does your ~/.hgrc look like? If you're using the fetch extension, it should be opening up a configured merge tool when a conflict is detected.
I detailed my full mercurial config a while back in a blog post where I use kdiff3 as my merge tool.
When doing an "hg fetch" or an "hg merge" (after a conflict is detected) it launches kdiff3 as you'd expect and lets me resolve the merge.