From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from fhigh-b8-smtp.messagingengine.com (fhigh-b8-smtp.messagingengine.com [202.12.124.159]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E0B94378D7D for ; Thu, 23 Jul 2026 18:31:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.159 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784831468; cv=none; b=JN2Vv3Unj8VqX9tf+HZamCjS4qAtoa02d9AnoQ5KxRmZTpGmTLQHqV5G54wjpFv8gDH9ilhrp7VeFJyL+jPVuzEe/Xnkg4K9AWmnLxCTG3PnIEFyV34J+ZZMjEk5/Kpystd4tWHQQoyPcIHgbRXeiUpH6EF8BUK4QPFQ+kJFhh8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784831468; c=relaxed/simple; bh=quUqUfI0D1ZpOHEI4dtBw872uFl6HbDI+fuhQjCmgiU=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=OlCAd5wvbqvX4AEWKVKtIC6HSO5D/lnQaSMXt7Ypn4017HCsSBbuN9/F7pmRn4IhVlwIWZsYWAIx83dXOK8gVamFKqJqP0Uav1G0BoiYAUHF3E1fNuqx9/8z1QaRZ8eiZVPgLr9jW4HuL5ZnaEQpmvtED94+jN7L8jruhl+IhJM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com; spf=pass smtp.mailfrom=pobox.com; dkim=pass (2048-bit key) header.d=pobox.com header.i=@pobox.com header.b=JlY7HI2o; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=BhT0DeFZ; arc=none smtp.client-ip=202.12.124.159 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pobox.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pobox.com header.i=@pobox.com header.b="JlY7HI2o"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="BhT0DeFZ" Received: from phl-compute-02.internal (phl-compute-02.internal [10.202.2.42]) by mailfhigh.stl.internal (Postfix) with ESMTP id C8D4E7A0177; Thu, 23 Jul 2026 14:30:59 -0400 (EDT) Received: from phl-frontend-02 ([10.202.2.161]) by phl-compute-02.internal (MEProxy); Thu, 23 Jul 2026 14:30:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pobox.com; h=cc :cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1784831459; x=1784917859; bh=RDAVycOjkC v5LrhMdlcRhxmSoi1f82B8J2E/ahk3gYk=; b=JlY7HI2osam2KNctKeI4l4cIRe knxxAvinmd9zpg17MKmUlOMvFidEwhNkZHa43jUjnzY+wde4B/MZXKEeRR9KUJgQ 2uS/aw+kPOSIvdLYSBygvoTtBBrCP+SlTrHYmnH3LCguBvnCi9PYmcnEHkJ08BN9 v81NHkJ8n4q6NxD/dgf3OuTLxna9tod0ttcMvptGmv5uGMwjr7rYBHWdCrnakGii bSB7TU3AkhmL2sM6sQ5RxPvwK3o4madz+H+7Q2CvAr/rf00JewW8dpwNPIy8gZBs e6j1C3wZlAiGiADzsop8o40fr1Rd1MADHq+lT2HkJ2MwjHc1gK9hZGzwk6mQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t= 1784831459; x=1784917859; bh=R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kF77d1PldXtRdq6VBFzSgQ X-ME-Proxy: Feedback-ID: if26b431b:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 23 Jul 2026 14:30:58 -0400 (EDT) From: Junio C Hamano To: "Lucas Zamboni Orioli via GitGitGadget" Cc: git@vger.kernel.org, Ben Knoble , Lucas Zamboni Orioli Subject: Re: [PATCH v2 2/2] mv: check for missing destination directory before renaming In-Reply-To: <1a790e001610d3324ec45d86ac67ca5720678cb8.1784812390.git.gitgitgadget@gmail.com> (Lucas Zamboni Orioli via GitGitGadget's message of "Thu, 23 Jul 2026 13:13:10 +0000") References: <1a790e001610d3324ec45d86ac67ca5720678cb8.1784812390.git.gitgitgadget@gmail.com> Date: Thu, 23 Jul 2026 11:30:57 -0700 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain "Lucas Zamboni Orioli via GitGitGadget" writes: > + /* > + * If we are going to move SRC to DST on disk, DST's leading > + * directories must already exist. > + */ /* * Our multi-line comment is formatted like this. The * asterisks align vertically. */ > + if (!(modes[i] & (INDEX | SPARSE | SKIP_WORKTREE_DIR)) && > + !(dst_mode & (SKIP_WORKTREE_DIR | SPARSE))) { > + char *dst_dir = xstrdup(dst); > + char *slash = strrchr(dst_dir, '/'); > + > + if (slash) { > + struct stat dir_st; > + *slash = '\0'; > + if (lstat(dst_dir, &dir_st) < 0 && errno == ENOENT) { > + free(dst_dir); > + bad = _("destination directory does not exist"); > + goto act_on_entry; > + } > + } > + free(dst_dir); > + } lstat() can succeed and 'dir_st' may indicate something other than a directory (for example, a symbolic link or a regular file). Alternatively, it can fail with ENOTDIR when, for example, 'dst_dir' is 'a/b/c' and 'a/b' is a file rather than a directory. Both cases will cause 'git mv' into a path assumed to be a directory to fail. Shouldn't we handle these conditions as well?