From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ramkumar Ramachandra Subject: [PATCH 15/18] reset: Make reset remove the sequencer state Date: Tue, 19 Jul 2011 22:47:53 +0530 Message-ID: <1311095876-3098-16-git-send-email-artagnon@gmail.com> References: <1311095876-3098-1-git-send-email-artagnon@gmail.com> Cc: Jonathan Nieder , Junio C Hamano , Christian Couder , Daniel Barkalow , Jeff King To: Git List X-From: git-owner@vger.kernel.org Tue Jul 19 19:20:08 2011 Return-path: Envelope-to: gcvg-git-2@lo.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1QjDxm-0003RJ-LU for gcvg-git-2@lo.gmane.org; Tue, 19 Jul 2011 19:20:07 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751231Ab1GSRUA (ORCPT ); Tue, 19 Jul 2011 13:20:00 -0400 Received: from mail-pv0-f174.google.com ([74.125.83.174]:36451 "EHLO mail-pv0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750803Ab1GSRT7 (ORCPT ); Tue, 19 Jul 2011 13:19:59 -0400 Received: by mail-pv0-f174.google.com with SMTP id 12so4030753pvg.19 for ; Tue, 19 Jul 2011 10:19:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=y/W+ZMzPsf0vgw5ToB83XArHKsPh3z7B/n6CKyLedb0=; b=qeznxXnbrHfa5LSAhkMVE+WZGD47mdLsdp+eP+ty8OEI3iDzfBvic9Tz0lQ9YnVOG2 sYM6XTuevhAK4RGnibi9MvVATb7WJD+L0cU5QKmgXJ+7lo2x34yw1I5wmF8uG9J33wsM u6ZnQnUFVz9vKV+mXCGD9yaKhnJAPztQFwkfo= Received: by 10.142.225.2 with SMTP id x2mr2253415wfg.120.1311095999668; Tue, 19 Jul 2011 10:19:59 -0700 (PDT) Received: from localhost.localdomain ([203.110.240.41]) by mx.google.com with ESMTPS id r12sm4276415wfe.1.2011.07.19.10.19.54 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 19 Jul 2011 10:19:58 -0700 (PDT) X-Mailer: git-send-email 1.7.4.rc1.7.g2cf08.dirty In-Reply-To: <1311095876-3098-1-git-send-email-artagnon@gmail.com> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: Years of muscle memory have trained users to use "git reset --hard" to remove the branch state after any sort operation. Make it also remove the sequencer state to facilitate this established workflow: $ git cherry-pick foo..bar ... conflict encountered ... $ git reset --hard # Oops, I didn't mean that $ git cherry-pick quux..bar ... cherry-pick succeeded ... Guard against accidental removal of the sequencer state by providing one level of "undo". In the first "reset" invocation, ".git/sequencer" is moved to ".git/sequencer-old"; it is completely removed only in the second invocation. Helped-by: Jonathan Nieder Signed-off-by: Ramkumar Ramachandra --- branch.c | 2 ++ t/7106-reset-sequence.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 0 deletions(-) create mode 100755 t/7106-reset-sequence.sh diff --git a/branch.c b/branch.c index c0c865a..d06aec4 100644 --- a/branch.c +++ b/branch.c @@ -3,6 +3,7 @@ #include "refs.h" #include "remote.h" #include "commit.h" +#include "sequencer.h" struct tracking { struct refspec spec; @@ -228,4 +229,5 @@ void remove_branch_state(void) unlink(git_path("MERGE_MSG")); unlink(git_path("MERGE_MODE")); unlink(git_path("SQUASH_MSG")); + remove_sequencer_state(0); } diff --git a/t/7106-reset-sequence.sh b/t/7106-reset-sequence.sh new file mode 100755 index 0000000..c61c62d --- /dev/null +++ b/t/7106-reset-sequence.sh @@ -0,0 +1,43 @@ +#!/bin/sh + +test_description='Test interaction of reset --hard with sequencer + + + anotherpick: rewrites foo to d + + picked: rewrites foo to c + + unrelatedpick: rewrites unrelated to reallyunrelated + + base: rewrites foo to b + + initial: writes foo as a, unrelated as unrelated +' + +. ./test-lib.sh + +pristine_detach () { + git checkout -f "$1^0" && + git read-tree -u --reset HEAD && + git clean -d -f -f -q -x +} + +test_expect_success setup ' + echo unrelated >unrelated && + git add unrelated && + test_commit initial foo a && + test_commit base foo b && + test_commit unrelatedpick unrelated reallyunrelated && + test_commit picked foo c && + test_commit anotherpick foo d && + git config advice.detachedhead false + +' + +test_expect_success 'reset --hard cleans up sequencer state, providing one-level undo' ' + pristine_detach initial && + test_must_fail git cherry-pick base..anotherpick && + test_path_is_dir .git/sequencer && + git reset --hard && + test_path_is_missing .git/sequencer && + test_path_is_dir .git/sequencer-old && + git reset --hard && + test_path_is_missing .git/sequencer-old +' + +test_done -- 1.7.4.rc1.7.g2cf08.dirty