From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sudhanshu Shekhar Subject: [PATCH v5 2/2] t7102: add 'reset -' tests Date: Fri, 13 Mar 2015 23:48:36 +0530 Message-ID: <1426270716-22405-2-git-send-email-sudshekhar02@gmail.com> References: <1426270716-22405-1-git-send-email-sudshekhar02@gmail.com> Cc: Matthieu.Moy@grenoble-inp.fr, gitster@pobox.com, davvid@gmail.com, sunshine@sunshineco.com, Sudhanshu Shekhar To: git@vger.kernel.org X-From: git-owner@vger.kernel.org Fri Mar 13 19:20:06 2015 Return-path: Envelope-to: gcvg-git-2@plane.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YWUBp-0003am-5J for gcvg-git-2@plane.gmane.org; Fri, 13 Mar 2015 19:20:05 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030366AbbCMST7 (ORCPT ); Fri, 13 Mar 2015 14:19:59 -0400 Received: from mail-pa0-f43.google.com ([209.85.220.43]:34016 "EHLO mail-pa0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030363AbbCMST5 (ORCPT ); Fri, 13 Mar 2015 14:19:57 -0400 Received: by paceu11 with SMTP id eu11so31377103pac.1 for ; Fri, 13 Mar 2015 11:19:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=k3tOmelnWOGs9etxwhqrnR/5Gw37pXHyrD/e9K3AYpU=; b=Gyj6ZtQ5bRIi9Bs6cPrKup+YxVbQQguslnp5QtVfNQ/+F6PRNU1FSX6LF+WvEJFIL0 YyeptMAwb5o9rkvLPhIusfEvnfFRNN9Teei65jYsWJQjj5g8H8qmDj+qEOxqdI+G+GrD LGj0nNLlsmiKgJn/pTB50hu9ZL/0JDeIhJqCmtfzhWgc1KhMrC8GVBhXT5e6nMgeCG92 aDQmYqRXiC6dEU8BFrAzAYIWPfZouaZdqvk+zrZ+obaTDYpIwMzGmMNYrXSd8xdT5Wr3 RFygWUD8gCM91SSsSOGPoSMyqf/PSiNWStRKReecJgm+u7d788Z9O2w9OFxbsvFy9j9K 3HYg== X-Received: by 10.66.124.227 with SMTP id ml3mr106232660pab.28.1426270796235; Fri, 13 Mar 2015 11:19:56 -0700 (PDT) Received: from shekhar-Inspiron-N5110.iiit.ac.in ([14.139.82.6]) by mx.google.com with ESMTPSA id g10sm4611117pdm.29.2015.03.13.11.19.51 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 13 Mar 2015 11:19:55 -0700 (PDT) X-Mailer: git-send-email 2.3.1.279.ga2b2924 In-Reply-To: <1426270716-22405-1-git-send-email-sudshekhar02@gmail.com> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: Add following test cases: 1) Confirm error message when git reset is used with no previous branch 2) Confirm git reset - works like git reset @{-1} 3) Confirm "-" is always treated as a commit unless the -- file option is specified 4) Confirm "git reset -" works normally even when a file named @{-1} is present Helped-by: Eric Sunshine Helped-by: Matthieu Moy Helped-by: David Aguilar Signed-off-by: Sudhanshu Shekhar --- Eric: Thank you for pointing out the mistake. The '&&' after the Here Docs was causing the issue. I have removed the concatenation from there, hope that's okay. Regarding the @{-1} test case, I created it as a check for Junio's comment on the error message generated by "git reset -" when a file named @{-1} is there. Since, in this situation "git reset @{-1}" will return an error (but "reset -" shouldn't). I have renamed the folder to 'dash' as suggested by you, keeping the old name only where it made sense. t/t7102-reset.sh | 158 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) diff --git a/t/t7102-reset.sh b/t/t7102-reset.sh index 98bcfe2..18523c1 100755 --- a/t/t7102-reset.sh +++ b/t/t7102-reset.sh @@ -568,4 +568,162 @@ test_expect_success 'reset --mixed sets up work tree' ' test_cmp expect actual ' +test_expect_success 'reset - with no previous branch fails' ' + git init no_previous && + test_when_finished rm -rf no_previous && + ( + cd no_previous && + test_must_fail git reset - 2>actual + ) && + test_i18ngrep "ambiguous argument" no_previous/actual +' + +test_expect_success 'reset - while having file named - and no previous branch fails' ' + git init no_previous && + test_when_finished rm -rf no_previous && + ( + cd no_previous && + >- && + test_must_fail git reset - 2>actual + ) && + test_i18ngrep "ambiguous argument" no_previous/actual +' + + +test_expect_success \ + 'reset - in the presence of file named - with previous branch resets commit' ' + cat >expect <<-EOF + Unstaged changes after reset: + M - + M file + EOF + git init dash && + test_when_finished rm -rf dash && + ( + cd dash && + >- && + >file && + git add file - && + git commit -m "add base files" && + git checkout -b new_branch && + echo "random" >- && + echo "wow" >file && + git add file - && + git reset - >../actual + ) && + test_cmp expect actual +' +test_expect_success \ + 'reset - in the presence of file named - with -- option resets commit' ' + cat >expect <<-EOF + Unstaged changes after reset: + M - + M file + EOF + git init dash && + test_when_finished rm -rf dash && + ( + cd dash && + >- && + >file && + git add file - && + git commit -m "add base files" && + git checkout -b new_branch && + echo "random" >- && + echo "wow" >file && + git add file - && + git reset - -- >../actual + ) && + test_cmp expect actual +' + +test_expect_success 'reset - in the presence of file named - with -- file option resets file' ' + cat >expect <<-EOF + Unstaged changes after reset: + M - + EOF + git init dash && + test_when_finished rm -rf dash && + ( + cd dash && + >- && + >file && + git add file - && + git commit -m "add base files" && + git checkout -b new_branch && + echo "random" >- && + echo "wow" >file && + git add file - && + git reset -- - >../actual + ) && + test_cmp expect actual +' +test_expect_success \ + 'reset - in the presence of file named - with both pre and post -- option resets file' ' + cat >expect <<-EOF + Unstaged changes after reset: + M - + EOF + git init dash && + test_when_finished rm -rf dash && + ( + cd dash && + >- && + >file && + git add file - && + git commit -m "add base files" && + git checkout -b new_branch && + echo "random" >- && + echo "wow" >file && + git add file - && + git reset - -- - >../actual + ) && + test_cmp expect actual +' + +test_expect_success 'reset - works same as reset @{-1}' ' + git init dash && + test_when_finished rm -rf dash && + ( + cd dash && + echo "file1" >file1 && + git add file1 && + git commit -m "base commit" && + git checkout -b temp && + echo "new file" >file && + git add file && + git commit -m "added file" && + git reset - && + git status --porcelain >../actual && + git add file && + git commit -m "added file" && + git reset @{-1} && + git status --porcelain >../expect + ) && + test_cmp expect actual +' + +test_expect_success 'reset - with file named @{-1} succeeds' ' + cat >expect <<-EOF + Unstaged changes after reset: + M @{-1} + M file + EOF + git init dash && + test_when_finished rm -rf dash && + ( + cd dash && + echo "random" >@{-1} && + echo "random" >file && + git add @{-1} file && + git commit -m "base commit" && + git checkout -b new_branch && + echo "additional stuff" >>file && + echo "additional stuff" >>@{-1} && + git add file @{-1} && + git reset - >../actual + ) && + test_cmp expect actual +' + test_done -- 2.3.1.277.gd67f9d5.dirty