Mercurial: Track repo with .hg dir and work-tree in separate directories - mercurial

I have often used this approach to dot file management in git, where I create a bare git repo "~/.dotfiles" and us $HOME as a work tree. With the shell alias config I can then add dot files from the home dir quickly (as in config add, config commit
alias config='git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME'
I wonder if a similar setup is possible in mercurial.

You can use a regular repository for that[^bare] and clone it with the share extension. Creating a new home dir as one-liner:
hg --config extensions.share= share $HOME/.dotfiles $HOME
For more information see hg help share. For information how to ignore changes to untracked files, see hg help hgignore.
[^bare]: If it is important for you to have no files in the .dotfiles, just hg update null in ~/.dotfiles. That’s the root of the repository (before anything got added). Mercurial needs no special bare state.

Related

Is there a Mercurial (hg) equivalent of `git remote -v`?

That is, does Mercurial have a command to tell where it was originally cloned from?
The following question seems to not serve that purpose: Mercurial repository identification
I can't recall special command for it, just because I always read repo's hgrc [paths] section by eye due to fact (hg help config)
The following special named paths exist:
"default"
The URL or directory to use when no source or remote is specified.
'hg clone' will automatically define this path to the location the
repository was cloned from.
but if you want hg command and trust hgrc's content (which can be edited at any time), you can use hg config paths.default which output key from repo-config, without warranties of using this URL for the whole lifetime of repo

Clone Mercurial repository into public_html

I want to clone my Mercurial repository into my /public_html folder on my web server. My Mercurial project looks like this...
- /ProjectName
- /public
- /application
- /config
- /library
What I want is to just get the contents of "ProjectName" into my /public_html folder. Unfortunately, cloning the repository includes "ProjectName" and all of the subfolders are in there.
Any idea how to accomplish this without a symbolic link?
Just to put it out there, you probably don't want a full clone in your public_html unless you really want every version that ever was out there on the web. There's nothing inherently wrong with that, but since you'll have a .hg in public_html people will even be able to clone your repository from it.
Instead consider using the hg archive command which exports all the files as they exist at a specific revision and places them wherever you want.
For example:
cd your_clone
hg archive --rev release /public_html
That takes the code pointed to by the release label (which could be a tag, bookmark, or branch head) and puts the files, but not a full-history clone, in /public_html.
I actually found an easy way to do this.
hg clone https://me#bitbucket.org/me/ProjectName "/home/website/public_html"
public_html has to be empty to clone the repository into it, so I moved everything out, cloned the repo, then moved the pre-existing files and folder back.
Here is a simple step that you can follow:
cd /public_html
hg init .
hg pull ../pathto/ProjectName/
This will pull all the files and folders under ProjectName in public_html without creating /public_html/ProjectName.
But it will still copy all the resources that are in the mercurial repository (Files and Folders) into your directory.

Would like to do a mercurial clone with filter of patterns in hgignore

Over time a number of the developers have committed files that were then added to the .hgignore. From what I hear there is no way to remove items from the history of mercurial, which is ok. But I also heard that there is a way to do a clone, I think using the convert plugin, to clone/export a repo while specifying which files to not include in the conversion.
I can't help but think that someone out there has a script that does this export/filter/convert using the patterns from the .hgignore file.
Has anyone created such a beast?
You could create a filemap from .hgignore doing something like this:
hg clone -U yourrepo temprepo # create a temp repo with no files in working dir
cd tmprepo
hg revert --all # put files in working dir
hg forget ** # un-add the files
hg status --ignored --no-status | sed 's/^/exclude /' > ../filemap
that will get you a filemap you can pass into hg convert that removes all the added files that would be ignored given your .hgignore.
Do understand though, that running convert creates a whole new repo that is unrelated to your previous repo. All existing clones will be unusable with the new one. It's not normally worth it.
hg convert is indeed the thing you want to use.
You will want to create a file map (just a text file) which will list all of the things you either want to include, exclude, or rename:
include subfolder
exclude subfolder/supersub
etc...
Read the following for a more concrete example:
https://www.mercurial-scm.org/wiki/ConvertExtension#A--filemap
Once you have created this file you will just use the following command:
$ hg convert --filemap my_file_map /path/to/source/repo /path/to/dest/repo
The source repo will not be modified and a dest repo will be created. I don't want to just copy verbatim what the documentation already says so here is the link:
How to keep just a subdirectory (or run on the mercurial repo):
https://www.mercurial-scm.org/wiki/ConvertExtension#Converting_from_Mercurial

How to commit to Sourceforge using Mercurial

I have directory named "Proyectos" with Django code inside.
I need to commit the project to Source Forge so my teacher can "download" all the code to his computer.
I think I should use some of these address:
http://phone-apps-djan.hg.sourceforge.net:8000/hgroot/phone-apps-djan/phone-apps-djan (read-only)
ssh://lucasab#phone-apps-djan.hg.sourceforge.net/hgroot/phone-apps-djan/phone-apps-djan (read/write)
I did this on Kubuntu:
lucas#lucas-Satellite-L305:~/Desarrollo/Python/Django/Proyectos$ hg clone http://phone-apps-djan.hg.sourceforge.net:8000/hgroot/phone-apps-djan/django-mercurial
but only the folder is created.
I'm a novice and didn't find how to do this. I followed some tutorials but I can't understand a lot of concepts.
I would appreciate some assistance with this, please.
Thanks in advance.
You have two different address to access your Mercurial repository on sourceforge :
http://phone-apps-djan.hg.sourceforge.net:8000/hgroot/phone-apps-djan/phone-apps-djan (read-only), like said after the address, this one is read-only, it is for everyone to clone your project, so they can see the sources and compile / use it. There's no authentication. When you use this address, Mercurial use the HTTP protocol to pull the changes.
ssh://lucasab#phone-apps-djan.hg.sourceforge.net/hgroot/phone-apps-djan/phone-apps-djan (read/write), you can write to your repository through this address, but you have to authenticate yourself (you'll have to enter your password) and Mercurial use the SSH protocol to do that. You can also see your sourceforge username in the address.
First of all, you must do another clone of your project with the second address, otherwise you won't be able to commit. Just cd in a new directory and do :
hg clone ssh://lucasab#phone-apps-djan.hg.sourceforge.net/hgroot/phone-apps-djan/phone-apps-djan
You should be prompted for your sourceforge account password.
Then, you can cd in the newly created directory, do all your changes, add files, etc. When you're done, you can do a hg commitand then a hg push to publish the modification to your repository. If you add new file to the directory don't forget to do a hg add or hg addremove.
You can find a really good and simple tutorial about mercurial on Hg Init, you should read it and try to understand the workflow before doing anything on sourceforge.
Good luck with your project :)
Many thanks to Rob Sobers and Krtek for their answers. I finally could add all my files to SourceForge. I followed their instructions and everything went fine, although I had some minor complications.
This is the answer to my questions step by step:
Over the folder "Proyectos" I did:
hg clone ssh://lucasab#phone-apps-djan.hg.sourceforge.net/hgroot/phone-apps-djan/phone-apps-djan and entered the password for my SourceForge account. A folder "phone-apps-djan" was created.
hg add after I cd into phone-apps-djan and copied all the files of my project into that folder.
hg commit. There was an error at this point: abort: no username supplied (see "hg help config"). So I created a file named .hgrc in my home dir and added these lines:
[ui]
username = my username at sourceforce <the mail address I supplied when registering>
verbose = True
Then I re-entered hg commit.
hg push. The follow error message was displayed: abort: repository default-push not found!. Then I just re-edited the .hgrc file created on the last step and added:
[paths]
default = ssh://lucasab#phone-apps-djan.hg.sourceforge.net/hgroot/phone-apps-djan/phone-apps-dja
I really don't understand what happened here because the .hg directory in my repo already contains a hgrc file with that path :(. Anyway, I did hg push again.
And that was all.
Doing hg clone downloaded the repository to your computer. Now, to update your working directory (so you can work with the files), type hg update.
When you're done making changes, type hg commit to record them. When you're ready upload your changes to SourceForge, type hg push http://path/to/repo. Make sure you push up to the correct repository!

how do i setup a local working directory to work with a local repo using Mercurial

Following is the scenario: I have a remote Mercurial repository at ssh://remotehost//dir/repo and I am able to clone it to a local host "pandora" in directory /home/user/localrepo/.
Now, I have a superset of this remote repository, where I add my own testing framework, but do not want to merge to the main depot until I am certain it works. So I clone this "local" repo to /home/user/workingdir/ but when I issue the command to do so
$ hg clone /home/user/localrepo/
only the repository folder gets copied none of the files get copied.
I'm not sure what you mean when you say that "only the repo folders gets copied". So there's two things you can try :
Try to do a hg update in your new clone.
List the directory in /home/user/workingdir and if there is a directory name localrepo in it, this is actually your repository. To clone in the current directory, you must do hg clone /home/user/localrepo .
This sounds odd but try a few things:
First in the local repo that you cloned from do a
hg status -A
are all the files that you think should be in there in there? If not are you at the tip of the repo.
You can see what revision you are at with
hg parent
If you want to just go to the tip do hg update
If there still aren't any files listed in the repo do the same to check the one on the server.
If there aren't any files on the server you will need to add all of the files you want mercurial to track, mercurial doesn't automagically start tracking files in the repo location.
(Use hg add --all to add all of the file in the entire directory tree under the repo location.)
If there are files in the local repo, check the testing area and make sure that it is on the proper changeset.