--- /dev/null
+Return-Path: <jani@nikula.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by arlo.cworth.org (Postfix) with ESMTP id 7755F6DE1502\r
+ for <notmuch@notmuchmail.org>; Sat, 5 Sep 2015 02:35:42 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.503\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.503 tagged_above=-999 required=5 tests=[AWL=0.217,\r
+ RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01]\r
+ autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id GCwYthGC22yN for <notmuch@notmuchmail.org>;\r
+ Sat, 5 Sep 2015 02:35:39 -0700 (PDT)\r
+Received: from mail-wi0-f181.google.com (mail-wi0-f181.google.com\r
+ [209.85.212.181])\r
+ by arlo.cworth.org (Postfix) with ESMTPS id 7CE836DE14C7\r
+ for <notmuch@notmuchmail.org>; Sat, 5 Sep 2015 02:35:38 -0700 (PDT)\r
+Received: by wicfx3 with SMTP id fx3so43312752wic.1\r
+ for <notmuch@notmuchmail.org>; Sat, 05 Sep 2015 02:35:36 -0700 (PDT)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+ d=1e100.net; s=20130820;\r
+ h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\r
+ :references;\r
+ bh=KebmCKtD+8/r1KiZ5d9C+8ZuarOPzuHiC+1dG7Dcxgo=;\r
+ b=InAflQb3QbKolBCaJlSzSoIZPw+JC22ZEXX+7rGB8UaSdtTQlEFjFhKVprX8vMN/+N\r
+ DbAByvlR5mJaMQSbq1WIAreXMVZ+68lMaPJ/TQL3ZtlmyUrKpd5KrTo9/7pSRXIFu40e\r
+ teUK/8bbH2h/GEPUJHbfVdH+1f4v6v9w1Aeb6d9AaFv440/VsgJ7EU68SGJHzthPegAF\r
+ neMmEPYQKfRc8THAD2V+EaLNPdfND2SzGGQ0xxEIyuEeiI1JGMFDYmyoLin+vOCyuKNp\r
+ 14v5Thwy21o6NgtTI2XYn3B6voAiccGLmWCzh+OmZrhrXedFiT173v77DodQUJHFOI22\r
+ g5OQ==\r
+X-Gm-Message-State:\r
+ ALoCoQkn5C8XM62u6JIFs48ljEnGHEfkl9UWL8p7zlO66/ej6xq8yQabdHX/85cvpz8GwxhMGRU3\r
+X-Received: by 10.180.91.131 with SMTP id ce3mr15967415wib.84.1441445736378;\r
+ Sat, 05 Sep 2015 02:35:36 -0700 (PDT)\r
+Received: from localhost (mobile-access-bcee4f-131.dhcp.inet.fi.\r
+ [188.238.79.131])\r
+ by smtp.gmail.com with ESMTPSA id s9sm8951926wjy.16.2015.09.05.02.35.35\r
+ (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
+ Sat, 05 Sep 2015 02:35:35 -0700 (PDT)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: Mark Walters <markwalters1009@gmail.com>,\r
+ notmuch@notmuchmail.org\r
+Subject: [PATCH 1/2] HACK: test: test folder renames\r
+Date: Sat, 5 Sep 2015 12:35:30 +0300\r
+Message-Id: <1441445731-4362-1-git-send-email-jani@nikula.org>\r
+X-Mailer: git-send-email 2.1.4\r
+In-Reply-To: <87siray6th.fsf@qmul.ac.uk>\r
+References: <87siray6th.fsf@qmul.ac.uk>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.18\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sat, 05 Sep 2015 09:35:42 -0000\r
+\r
+On Sun, 23 Feb 2014, Mark Walters <markwalters1009@gmail.com> wrote [1]:\r
+> I was experimenting with letting notmuch new take an argument to tell it\r
+> to scan only a particular directory (and sub-directories) for new\r
+> messages. I came across the following strange behaviour which is also\r
+> present in master (with a fresh database)\r
+>\r
+> I have a bunch of maildirs in /home/mail: so folders .mail.foo/\r
+> .mail.bar/ each of which has cur/new/tmp and all the messages are in\r
+> cur.\r
+>\r
+> If I do mv .mail.foo .mail.bar/ and run notmuch new I get the expected\r
+> lots of renames (900 or so in the case I was trying). But if I then do\r
+> mv .mail.bar/.mail.foo . and run notmuch new almost all the messages get\r
+> removed (but 30 renames do get detected). If I then do touch .mail.foo/*\r
+> the messages get found again\r
+>\r
+> I am guessing the 30 renames might be because those 30 have duplicates\r
+> somewhere else.\r
+>\r
+> But the other behaviour has me puzzled.\r
+\r
+This test reproduces the problem for me, but it's not deterministic,\r
+and I've been unable to make it so. Thus there's a loop of 100\r
+attempts, and usually I hit the problem several times like this:\r
+\r
+ FAIL Rename folder back\r
+ --- T051-new-renames.27.expected 2014-02-23 21:37:10.121774241 +0000\r
+ +++ T051-new-renames.27.output 2014-02-23 21:37:10.121774241 +0000\r
+ @@ -1 +1 @@\r
+ -No new mail. Detected 10 file renames.\r
+ +No new mail. Removed 10 messages.\r
+ FAIL Files remain the same\r
+ --- T051-new-renames.28.expected 2014-02-23 21:37:10.133774652 +0000\r
+ +++ T051-new-renames.28.output 2014-02-23 21:37:10.133774652 +0000\r
+ @@ -1,13 +1,3 @@\r
+ -/path/to/test/tmp.T051-new-renames/mail/foo/msg-121\r
+ -/path/to/test/tmp.T051-new-renames/mail/foo/msg-122\r
+ -/path/to/test/tmp.T051-new-renames/mail/foo/msg-123\r
+ -/path/to/test/tmp.T051-new-renames/mail/foo/msg-124\r
+ -/path/to/test/tmp.T051-new-renames/mail/foo/msg-125\r
+ -/path/to/test/tmp.T051-new-renames/mail/foo/msg-126\r
+ -/path/to/test/tmp.T051-new-renames/mail/foo/msg-127\r
+ -/path/to/test/tmp.T051-new-renames/mail/foo/msg-128\r
+ -/path/to/test/tmp.T051-new-renames/mail/foo/msg-129\r
+ -/path/to/test/tmp.T051-new-renames/mail/foo/msg-130\r
+ /path/to/test/tmp.T051-new-renames/mail/bar/msg-131\r
+ /path/to/test/tmp.T051-new-renames/mail/bar/msg-132\r
+ /path/to/test/tmp.T051-new-renames/mail/bar/msg-133\r
+\r
+This test is not suitable for merging since it's not\r
+deterministic. But maybe it's good enough to assess the patch that\r
+follows.\r
+\r
+[1] id:87siray6th.fsf@qmul.ac.uk\r
+---\r
+ test/T051-new-renames.sh | 40 ++++++++++++++++++++++++++++++++++++++++\r
+ 1 file changed, 40 insertions(+)\r
+ create mode 100755 test/T051-new-renames.sh\r
+\r
+diff --git a/test/T051-new-renames.sh b/test/T051-new-renames.sh\r
+new file mode 100755\r
+index 000000000000..3c1515da1085\r
+--- /dev/null\r
++++ b/test/T051-new-renames.sh\r
+@@ -0,0 +1,40 @@\r
++#!/usr/bin/env bash\r
++test_description='"notmuch new" with directory renames'\r
++. ./test-lib.sh\r
++\r
++for loop in `seq 100`; do\r
++\r
++rm -rf ${MAIL_DIR}\r
++\r
++for i in `seq 10`; do\r
++ generate_message '[dir]=foo' '[subject]="Message foo $i"'\r
++done\r
++\r
++for i in `seq 10`; do\r
++ generate_message '[dir]=bar' '[subject]="Message bar $i"'\r
++done\r
++\r
++test_begin_subtest "Index the messages, round $loop"\r
++output=$(NOTMUCH_NEW)\r
++test_expect_equal "$output" "Added 20 new messages to the database."\r
++\r
++all_files=$(notmuch search --output=files \*)\r
++count_foo=$(notmuch count folder:foo)\r
++\r
++test_begin_subtest "Rename folder foo -> baz"\r
++mv ${MAIL_DIR}/foo ${MAIL_DIR}/baz\r
++output=$(NOTMUCH_NEW)\r
++test_expect_equal "$output" "No new mail. Detected $count_foo file renames."\r
++\r
++test_begin_subtest "Rename folder back baz -> foo"\r
++mv ${MAIL_DIR}/baz ${MAIL_DIR}/foo\r
++output=$(NOTMUCH_NEW)\r
++test_expect_equal "$output" "No new mail. Detected $count_foo file renames."\r
++\r
++test_begin_subtest "Files remain the same"\r
++output=$(notmuch search --output=files \*)\r
++test_expect_equal "$output" "$all_files"\r
++\r
++done\r
++\r
++test_done\r
+-- \r
+2.1.4\r
+\r