From patchwork Fri Feb 3 05:21:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Donnellan X-Patchwork-Id: 723404 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vF4xy6vWxz9s76 for ; Fri, 3 Feb 2017 16:22:46 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3vF4xy62JJzDqDC for ; Fri, 3 Feb 2017 16:22:46 +1100 (AEDT) X-Original-To: snowpatch@lists.ozlabs.org Delivered-To: snowpatch@lists.ozlabs.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3vF4xh4b2nzDqG5 for ; Fri, 3 Feb 2017 16:22:32 +1100 (AEDT) Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v135JFm8112493 for ; Fri, 3 Feb 2017 00:22:30 -0500 Received: from e23smtp04.au.ibm.com (e23smtp04.au.ibm.com [202.81.31.146]) by mx0a-001b2d01.pphosted.com with ESMTP id 28c3vgc8hu-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 03 Feb 2017 00:22:30 -0500 Received: from localhost by e23smtp04.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 3 Feb 2017 15:22:27 +1000 Received: from d23dlp02.au.ibm.com (202.81.31.213) by e23smtp04.au.ibm.com (202.81.31.210) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 3 Feb 2017 15:22:26 +1000 Received: from d23relay07.au.ibm.com (d23relay07.au.ibm.com [9.190.26.37]) by d23dlp02.au.ibm.com (Postfix) with ESMTP id 043D42BB0045 for ; Fri, 3 Feb 2017 16:22:26 +1100 (EST) Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by d23relay07.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v135MHaL33751128 for ; Fri, 3 Feb 2017 16:22:25 +1100 Received: from d23av02.au.ibm.com (localhost [127.0.0.1]) by d23av02.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v135Ls9k004438 for ; Fri, 3 Feb 2017 16:21:54 +1100 Received: from ozlabs.au.ibm.com (ozlabs.au.ibm.com [9.192.253.14]) by d23av02.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v135LsIo003993; Fri, 3 Feb 2017 16:21:54 +1100 Received: from ajd.ozlabs.ibm.com (haven.au.ibm.com [9.192.254.114]) (using TLSv1.2 with cipher AES128-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.au.ibm.com (Postfix) with ESMTPSA id 717C5A0105; Fri, 3 Feb 2017 16:21:29 +1100 (AEDT) From: Andrew Donnellan To: snowpatch@lists.ozlabs.org Date: Fri, 3 Feb 2017 16:21:25 +1100 X-Mailer: git-send-email 2.11.0 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 17020305-0012-0000-0000-0000020D638D X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17020305-0013-0000-0000-000006ED8963 Message-Id: <20170203052125.22790-1-andrew.donnellan@au1.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-02-03_04:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1612050000 definitions=main-1702030055 Subject: [snowpatch] [PATCH] git: force reset + clean the repository before applying patches X-BeenThere: snowpatch@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Continuous Integration for patch-based workflows List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: snowpatch-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "snowpatch" From: Russell Currey We've been seeing some strange heisenbugs where patches refuse to apply due to a dirty index. Do a hard reset and git clean when changing branches which may help with this. Signed-off-by: Russell Currey Signed-off-by: Andrew Donnellan --- already merged, for information only --- src/git.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/git.rs b/src/git.rs index e67caac..8443616 100644 --- a/src/git.rs +++ b/src/git.rs @@ -58,10 +58,45 @@ pub fn pull(repo: &Repository) -> Result { } pub fn checkout_branch(repo: &Repository, branch: &str) -> () { + let workdir = repo.workdir().unwrap(); // TODO: support bare repositories + + // Make sure there's no junk lying around before we switch + Command::new("git") + .arg("reset") + .arg("--hard") + .current_dir(&workdir) + .output() + .unwrap(); + + Command::new("git") + .arg("clean") + .arg("-f") // force remove files we don't need + .arg("-d") // ...including directories + .current_dir(&workdir) + .output() + .unwrap(); + repo.set_head(&format!("{}/{}", GIT_REF_BASE, &branch)) .unwrap_or_else(|err| panic!("Couldn't set HEAD: {}", err)); repo.checkout_head(Some(&mut CheckoutBuilder::new().force())) .unwrap_or_else(|err| panic!("Couldn't checkout HEAD: {}", err)); + + // Clean up again, just to be super sure + Command::new("git") + .arg("reset") + .arg("--hard") + .current_dir(&workdir) + .output() + .unwrap(); + + Command::new("git") + .arg("clean") + .arg("-f") // force remove files we don't need + .arg("-d") // ...including directories + .current_dir(&workdir) + .output() + .unwrap(); + () } pub fn apply_patch(repo: &Repository, path: &Path)