Skip to content
Snippets Groups Projects
test-illegal-contents.t 5.75 KiB
Check for contents we should refuse to export to git repositories (or
at least warn).

Load commonly used test logic
  $ . "$TESTDIR/testutil"

  $ hg init hg
  $ cd hg
  $ mkdir -p .git/hooks
  $ cat > .git/hooks/post-update <<EOF
  > #!/bin/sh
  > echo pwned
  > EOF
  $ fn_touch_escaped foo/git~100/wat bar/.gi\\u200ct/wut this/is/safe
  $ hg addremove
  adding .git/hooks/post-update
  adding bar/.gi\xe2\x80\x8ct/wut (esc)
  adding foo/git~100/wat
  adding this/is/safe
  $ hg ci -m "we should refuse to export this"
  $ hg book master
  $ hg gexport
  warning: skipping invalid path '.git/hooks/post-update'
  warning: skipping invalid path 'bar/.gi\xe2\x80\x8ct/wut'
  warning: skipping invalid path 'foo/git~100/wat'
  $ GIT_DIR=.hg/git git ls-tree -r --name-only  master
  this/is/safe
  $ hg gclear
  clearing out the git cache data
  $ hg gexport --config hggit.invalidpaths=keep
  warning: path '.git/hooks/post-update' contains an invalid path component
  warning: path 'bar/.gi\xe2\x80\x8ct/wut' contains an invalid path component
  warning: path 'foo/git~100/wat' contains an invalid path component
  $ GIT_DIR=.hg/git git ls-tree -r --name-only  master
  .git/hooks/post-update
  "bar/.gi\342\200\214t/wut"
  foo/git~100/wat
  this/is/safe
  $ cd ..

  $ rm -rf hg
  $ hg init hg
  $ cd hg
  $ mkdir -p nested/.git/hooks/
  $ cat > nested/.git/hooks/post-update <<EOF
  > #!/bin/sh
  > echo pwnd
  > EOF
  $ chmod +x nested/.git/hooks/post-update
  $ hg addremove
  adding nested/.git/hooks/post-update
  $ hg ci -m "also refuse to export this"
  $ hg book master
  $ hg gexport
  warning: skipping invalid path 'nested/.git/hooks/post-update'
  $ git clone .hg/git git
  Cloning into 'git'...
  done.
  $ rm -rf git

We can trigger an error:

  $ hg -q gclear
  $ hg --config hggit.invalidpaths=abort gexport
  abort: invalid path 'nested/.git/hooks/post-update' rejected by configuration
  (see 'hg help hggit' for details)
  [255]

We can override if needed: