Foreign Extension

This extension is not distributed with Mercurial.

Author: Martin Blais

Source code:

Web page:

Compatibility: Mercurial 0.9.5 and beyond.


A Mercurial extension that allows the user to quickly deal with foreign files.

This script allows you to add or delete files that are present but unknown to a repository. It deals with the case where you have been working for a while in a repository and forgot to tell Mercurial to add some files before committing, or want to cleanup and delete some of those files lying around.

Foreign runs 'status' on the given directories, to find out which files are unaccounted for and for each of these files, it interactively asks you what to do with it (commands are invoked with one keystroke):

The script works interactively and is meant to allow you to quickly deal with the forgotten files in a checkout.



Configure your .hgrc to enable the extension by adding following lines:

foreign =

Place somewhere accessible from your PYTHONPATH.

Usage Scenario

Here is a example repository with some modifications and unknown files in it.

  banane:~/work/3rdparty$ hg status
  A doc/diagram.dia
  R bin/pgrphack
  ! bin/fghack
  ? doc/project-docs.pdf
  ? doc/project-docs.txt
  ? share/
  ? share/

Here is an example session running 'hg foreign' to prepare it for commit.

  banane:~/work/3rdparty$ hg foreign
  ? doc/project-docs.pdf
  ? doc/project-docs.txt
  ? share/
  ? share/
  ! bin/fghack

  => [Add|Delete|Ignore|Skip|View|Quit]     2027120  doc/project-docs.pdf  ? i
  Add ignore pattern for 'doc/project-docs.pdf'
  => [Add|Delete|Ignore|Skip|View|Quit]       34743  doc/project-docs.txt  ? a
  Added 'doc/project-docs.txt'
  => [Add|Delete|Ignore|Skip|View|Quit]      218622  share/  ? a
  Added 'share/'
  => [Add|Delete|Ignore|Skip|View|Quit]           0  share/  ? d
  Deleted '/home/blais/work/3rdparty/share/'
  => [Revert|Delete|Skip|Quit]                    0  bin/fghack  ? d
  Removed 'bin/fghack'


ForeignExtension (last edited 2012-11-06 15:08:58 by abuehl)