Patchwork [3,of,9] export: do not start pager if output will be written to file

login
register
mail settings
Submitter Yuya Nishihara
Date April 12, 2018, 4:17 p.m.
Message ID <18bead1ff6b9b9d0df3e.1523549826@mimosa>
Download mbox | patch
Permalink /patch/30806/
State Accepted
Headers show

Comments

Yuya Nishihara - April 12, 2018, 4:17 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1523536427 -32400
#      Thu Apr 12 21:33:47 2018 +0900
# Node ID 18bead1ff6b9b9d0df3e6b0a7aea2fd358ce1244
# Parent  aa00793f5b3567c6768e8f7be43c3043ea29f536
export: do not start pager if output will be written to file

A copy of 3b569745af6c.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1971,8 +1971,14 @@  def export(ui, repo, *changesets, **opts
         ui.note(_('exporting patches:\n'))
     else:
         ui.note(_('exporting patch:\n'))
-    ui.pager('export')
-    cmdutil.export(repo, revs, fntemplate=opts.get('output'),
+
+    fntemplate = opts.get('output')
+    if cmdutil.isstdiofilename(fntemplate):
+        fntemplate = ''
+
+    if not fntemplate:
+        ui.pager('export')
+    cmdutil.export(repo, revs, fntemplate=fntemplate,
                  switch_parent=opts.get('switch_parent'),
                  opts=patch.diffallopts(ui, opts))
 
diff --git a/tests/test-pager.t b/tests/test-pager.t
--- a/tests/test-pager.t
+++ b/tests/test-pager.t
@@ -322,6 +322,37 @@  A command with --output option:
   $ hg cat -r0 a --output=-
   paged! 'a\n'
   $ hg cat -r0 a --output=out
+
+  $ hg export -r0
+  paged! '# HG changeset patch\n'
+  paged! '# User test\n'
+  paged! '# Date 0 0\n'
+  paged! '#      Thu Jan 01 00:00:00 1970 +0000\n'
+  paged! '# Node ID 1f0dee641bb7258c56bd60e93edfa2405381c41e\n'
+  paged! '# Parent  0000000000000000000000000000000000000000\n'
+  paged! 'add a\n'
+  paged! '\n'
+  paged! '\x1b[0;1mdiff -r 000000000000 -r 1f0dee641bb7 a\x1b[0m\n'
+  paged! '\x1b[0;31;1m--- /dev/null\tThu Jan 01 00:00:00 1970 +0000\x1b[0m\n'
+  paged! '\x1b[0;32;1m+++ b/a\tThu Jan 01 00:00:00 1970 +0000\x1b[0m\n'
+  paged! '\x1b[0;35m@@ -0,0 +1,1 @@\x1b[0m\n'
+  paged! '\x1b[0;32m+a\x1b[0m\n'
+  $ hg export -r0 -o -
+  paged! '# HG changeset patch\n'
+  paged! '# User test\n'
+  paged! '# Date 0 0\n'
+  paged! '#      Thu Jan 01 00:00:00 1970 +0000\n'
+  paged! '# Node ID 1f0dee641bb7258c56bd60e93edfa2405381c41e\n'
+  paged! '# Parent  0000000000000000000000000000000000000000\n'
+  paged! 'add a\n'
+  paged! '\n'
+  paged! '\x1b[0;1mdiff -r 000000000000 -r 1f0dee641bb7 a\x1b[0m\n'
+  paged! '\x1b[0;31;1m--- /dev/null\tThu Jan 01 00:00:00 1970 +0000\x1b[0m\n'
+  paged! '\x1b[0;32;1m+++ b/a\tThu Jan 01 00:00:00 1970 +0000\x1b[0m\n'
+  paged! '\x1b[0;35m@@ -0,0 +1,1 @@\x1b[0m\n'
+  paged! '\x1b[0;32m+a\x1b[0m\n'
+  $ hg export -r0 -o out
+
   $ rm out
 
 Put annotate in the ignore list for pager: