From patchwork Wed Sep 8 01:43:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12479749 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 300EFC433F5 for ; Wed, 8 Sep 2021 01:43:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 122A060555 for ; Wed, 8 Sep 2021 01:43:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346951AbhIHBpA (ORCPT ); Tue, 7 Sep 2021 21:45:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346851AbhIHBo4 (ORCPT ); Tue, 7 Sep 2021 21:44:56 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7BA02C06175F for ; Tue, 7 Sep 2021 18:43:49 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id z9-20020a7bc149000000b002e8861aff59so341123wmi.0 for ; Tue, 07 Sep 2021 18:43:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=pyp3qAMf8e8cfZ5TT1yj3l5tVqRBPMrlSGBm6ukHeSk=; b=IsQj3UfdfbvKgm6GMDio3bGtN34VssRyPeF5CnHcDBxZcTP8XWC+7n8iICfDkVY5kv UoLWPkooSnwwZlIZDbCjH1HXtEFq8OvqDgSrL48FvQvF3rTTB4uGX+BqjfUsmEFUFwft vDVdvJ1aN5RaEIGhkUexYUO2n8FW/6VOaDegbbltGvU4dLQ6ZNjS7Dtd5v5a7W0uKaG7 po1zG0svZonHNE2WHFBXGDHzxI8M7fFwc++sbghPj7LUSwh9Vk3tR15/EPVlqXwyhOX+ AGVBGEPqD1WDr5Te7wJdnN2GFjCcWrRGFSbZoUe+WVNAaY9YOyn5+25J6bMgPiiBf7rc PkTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=pyp3qAMf8e8cfZ5TT1yj3l5tVqRBPMrlSGBm6ukHeSk=; b=Oo62y5juNYmVfDHzbs8QYZEZyJwJ5pmCXMMZz6TnSke/ZziFCT7urTBzVgPWsGkhoD 1F/t1nKp9fIFCapDCmkFgZcAv5gYyXsnIUSfg5xPE4DMHVvtfW5ADZQ3ODoprK6DnwY3 I7D37as6iaEZVL1Znm+zOj5H/MTZ8v+kjV8lNagW7g+boCi5XkYk45vvMGf/9ll/RHBd wPmiBCOTM+sqWldbkb8GPIUVhgCrt9yqp2BgBQndzvFag49X5Gf5SrpS565Vo2oDpSo0 fdX4rrzF8WTnfwsah+IomwFDLrJmdHCgw2R+VZ1kFGW3ShyPiFqH146rvUP9Tlbdlfwc +6CQ== X-Gm-Message-State: AOAM530TVLs2hIRO82SNMGHyDOamZAjnYv9l1bILJz5D0bvkFIJ/HxWJ oJ3FDUUMW8C9+5JAu7Povj8+gQpgclM= X-Google-Smtp-Source: ABdhPJzSe7PkSevkvPYuyYw/R96GtVs7NFwW2loWdKs+oixK5/13V5ZG3lZb/d8fk4nGyUZGaH6zlQ== X-Received: by 2002:a05:600c:4848:: with SMTP id j8mr1006758wmo.13.1631065428200; Tue, 07 Sep 2021 18:43:48 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id x9sm544713wmi.30.2021.09.07.18.43.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 18:43:47 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Wed, 08 Sep 2021 01:43:44 +0000 Subject: [PATCH 1/3] t3903: document a pair of directory/file bugs Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren Signed-off-by: Elijah Newren --- t/t3903-stash.sh | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh index 873aa56e359..0727a494aa4 100755 --- a/t/t3903-stash.sh +++ b/t/t3903-stash.sh @@ -1307,4 +1307,42 @@ test_expect_success 'stash -c stash.useBuiltin=false warning ' ' test_must_be_empty err ' +test_expect_failure 'git stash succeeds despite directory/file change' ' + test_create_repo directory_file_switch_v1 && + ( + cd directory_file_switch_v1 && + test_commit init && + + test_write_lines this file has some words >filler && + git add filler && + git commit -m filler && + + git rm filler && + mkdir filler && + echo contents >filler/file && + cp filler/file expect && + git stash push + ) +' + +test_expect_failure 'git stash can pop directory/file saved changes' ' + test_create_repo directory_file_switch_v2 && + ( + cd directory_file_switch_v2 && + test_commit init && + + test_write_lines this file has some words >filler && + git add filler && + git commit -m filler && + + git rm filler && + mkdir filler && + echo contents >filler/file && + cp filler/file expect && + git stash push --include-untracked && + git stash apply --index && + test_cmp expect filler/file + ) +' + test_done From patchwork Wed Sep 8 01:43:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12479751 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B719AC433FE for ; Wed, 8 Sep 2021 01:43:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A2A0561132 for ; Wed, 8 Sep 2021 01:43:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346959AbhIHBpB (ORCPT ); Tue, 7 Sep 2021 21:45:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346864AbhIHBo5 (ORCPT ); Tue, 7 Sep 2021 21:44:57 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05060C0613CF for ; Tue, 7 Sep 2021 18:43:50 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id d6so704871wrc.11 for ; Tue, 07 Sep 2021 18:43:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=dXwllSK3ejTtDVxke93zl6uYcgErPFrnWumJWcE2M28=; b=H0u80r8m6hFI9XFG+dkUuu6nAmnt6E2bicUViQe7iSb5meQhvoyBpaLaVyy7+aRM8D vpCBXbVdk7x6Un6xu2K0FYxazS019DbrHa6CPfYd2YrF2jM5XFILWDYKwbrrcKkgOxKf 1K7hMsZzSG4+VAOPqOPfR8n8eNZZ2reJh3VhuaKZCfA0D2xdyR9150Le9OpyTFF6v1kM BTjm0hS0DvP/JsbJs5AVZK6szB0PE3iwKQw4lVSo89Szu3bTZCju/JrYN+9lVJ3E+Jec KdTVmHbC96Ytk938T1j1kJJXRf2UMn4zunbjLyiWBPRHcixyztX29G7a52H5R+7r4IcG SMWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=dXwllSK3ejTtDVxke93zl6uYcgErPFrnWumJWcE2M28=; b=ihz50+A9smRFOYOBeD0sG6A36P5N0WvUPWb5N5vwDgo+JQESvMTshKdG97ogtjg1qH QIcAaDCqXbHuoms0XyspGDI9md1RtOLdEsaTacrHS634ZtqaxNWgrbdoIXfABll/VnFG CsBX2/p+KvspqsikfwmDZ8RgFzIQv62WbBoZpljbrqn4XYS15HrQpdKVAoh28DT3iBIz QB+rYexh8YwhT429+frpXOb0tZ/TCz013u8kLybk7I9ZUmB1EUmQ5IycO9e4hRGC4gdn BD1NGJNrdqM7Vt2ylr/xc4uRPwmojVPb43O3DZeELZfOB8NAfuwgZ2wq6ob/9CIdKXrx hLbg== X-Gm-Message-State: AOAM532Rn7LF+XKR4O5qsOkoRbo2pnEoyQgKJkl9dkahlsIsBtmtgHWA +HnOQB0xHAG7Bis2v4rkY0qIE7L45yc= X-Google-Smtp-Source: ABdhPJx2W/rTTLcy7i2MwW1FZTVxzcdlq+BzouUA3c+kxyh1+KQBpH4cnkf0u+F+t8sIW2bdYwlMsA== X-Received: by 2002:adf:ce8d:: with SMTP id r13mr1153211wrn.18.1631065428678; Tue, 07 Sep 2021 18:43:48 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id a6sm636553wmb.7.2021.09.07.18.43.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 18:43:48 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Wed, 08 Sep 2021 01:43:45 +0000 Subject: [PATCH 2/3] stash: avoid feeding directories to update-index Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren When a file is removed from the cache, but there is a file of the same name present in the working directory, we would normally treat that file in the working directory as untracked. However, in the case of stash, doing that would prevent a simple 'git stash push', because the untracked file would be in the way of restoring the deleted file. git stash, however, blindly assumes that whatever is in the working directory for a deleted file is wanted and passes that path along to update-index. That causes problems when the working directory contains a directory with the same name as the deleted file. Add some code for this special case that will avoid passing directory names to update-index. Signed-off-by: Elijah Newren --- builtin/stash.c | 9 +++++++++ t/t3903-stash.sh | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/builtin/stash.c b/builtin/stash.c index 8f42360ca91..b85cf9d267e 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -313,6 +313,12 @@ static int reset_head(void) return run_command(&cp); } +static int is_path_a_directory(const char *path) +{ + struct stat st; + return (!lstat(path, &st) && S_ISDIR(st.st_mode)); +} + static void add_diff_to_buf(struct diff_queue_struct *q, struct diff_options *options, void *data) @@ -320,6 +326,9 @@ static void add_diff_to_buf(struct diff_queue_struct *q, int i; for (i = 0; i < q->nr; i++) { + if (is_path_a_directory(q->queue[i]->one->path)) + continue; + strbuf_addstr(data, q->queue[i]->one->path); /* NUL-terminate: will be fed to update-index -z */ diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh index 0727a494aa4..fc74918ccc0 100755 --- a/t/t3903-stash.sh +++ b/t/t3903-stash.sh @@ -1307,7 +1307,7 @@ test_expect_success 'stash -c stash.useBuiltin=false warning ' ' test_must_be_empty err ' -test_expect_failure 'git stash succeeds despite directory/file change' ' +test_expect_success 'git stash succeeds despite directory/file change' ' test_create_repo directory_file_switch_v1 && ( cd directory_file_switch_v1 && From patchwork Wed Sep 8 01:43:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12479753 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ABEE3C4332F for ; Wed, 8 Sep 2021 01:43:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9796361132 for ; Wed, 8 Sep 2021 01:43:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346983AbhIHBpC (ORCPT ); Tue, 7 Sep 2021 21:45:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346899AbhIHBo5 (ORCPT ); Tue, 7 Sep 2021 21:44:57 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 818F1C061575 for ; Tue, 7 Sep 2021 18:43:50 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id b6so713325wrh.10 for ; Tue, 07 Sep 2021 18:43:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=BaX/CWU9N3jqABC+OWfBVOROIH/P8jSVAopIgXDvppU=; b=g9QN0hnQSrHnRRhKrS7/jgozjEG4hDzA1XD2XB2hk9OdwHkUsncqSirx7OyovfzSgP KbHStWlsDeCCDI31v+ZannnNJMuUmjWmnMTZSgSpKCvgzF6ty0rUNbfDFCGKjtGxJiNj 1vdg9E5891xtWapEkd0P7LRNQKylTctRAuFTcLVHec3vSwzGmphar2sdheXwOosGth9w QAs+8Apzg2GH164CZs+X8Tg4Htd/Tsoxbs2DqvnH55R/haDEkRIyqhg25OBiIqEsCSyr +Us9zN0MoLExMw9T8yEx/pUKPt+X7uP37F8VTtJ8hs48L4n789Envvh711xqNaYuyEM8 GzaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=BaX/CWU9N3jqABC+OWfBVOROIH/P8jSVAopIgXDvppU=; b=zj/Uy5C+wQNJZ+4HVm7GhC+b4CgIomovkWqMQa6jG75qLEQcInjO2K9wd8OvQ8rqhh gps8eJS7C1JwA/z6y3A1f5ahxfQ7TvnZM2yH3tPoJ+ibTiOdtNWoevC7m8EwdxIDkyaR Y8BVSEhvCsAfDMXVS/vJ2OUAA22efWoK8bjQew7EOD5qO97AhyD8+wbJNEFmTtFMo422 6w8B0qOwmHPc1Zq+rbvmfGCuw93IC7APhyBGWUMttf526L+sAu+LsvB1j+nCVm6Xpy1A 1p2yYlG6Me1bTGZq1F9JzJ0a+p1ou+lQBVMT4nAgmloo8zFinYKTlG1KpfgrL1rEWkTC hj7Q== X-Gm-Message-State: AOAM5302DpsXu3RK3IkOV/g3msH1QlWi9p/ONXzo3NvvGxHHRWmupOKN aK5+Sx65w3aVuCy/0ILg3vyxv+dmaIo= X-Google-Smtp-Source: ABdhPJxCaT5VSFwjVcxXzjcxghsvnpyuHzY9Zc/W8uwRGHmMM5bHV4LrPeceQjLBulLnmeR9p9HCBA== X-Received: by 2002:a05:6000:374:: with SMTP id f20mr1103855wrf.129.1631065429142; Tue, 07 Sep 2021 18:43:49 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id k14sm571210wri.46.2021.09.07.18.43.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 18:43:48 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Wed, 08 Sep 2021 01:43:46 +0000 Subject: [PATCH 3/3] stash: restore untracked files AFTER restoring tracked files Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren If a user deletes a file and places a directory of untracked files there, then stashes all these changes, the untracked directory of files cannot be restored until after the corresponding file in the way is removed. So, restore changes to tracked files before restoring untracked files. There is no similar problem to worry about in the opposite directory, because untracked files are always additive. Said another way, there's no way to "stash a removal of an untracked file" because if an untracked file is removed, git simply doesn't know about it. Signed-off-by: Elijah Newren --- builtin/stash.c | 6 +++--- t/t3903-stash.sh | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/builtin/stash.c b/builtin/stash.c index b85cf9d267e..9a1f6a5a854 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -530,9 +530,6 @@ static int do_apply_stash(const char *prefix, struct stash_info *info, } } - if (info->has_u && restore_untracked(&info->u_tree)) - return error(_("could not restore untracked files from stash")); - init_merge_options(&o, the_repository); o.branch1 = "Updated upstream"; @@ -567,6 +564,9 @@ static int do_apply_stash(const char *prefix, struct stash_info *info, unstage_changes_unless_new(&c_tree); } + if (info->has_u && restore_untracked(&info->u_tree)) + return error(_("could not restore untracked files from stash")); + if (!quiet) { struct child_process cp = CHILD_PROCESS_INIT; diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh index fc74918ccc0..bfd3158a502 100755 --- a/t/t3903-stash.sh +++ b/t/t3903-stash.sh @@ -1325,7 +1325,7 @@ test_expect_success 'git stash succeeds despite directory/file change' ' ) ' -test_expect_failure 'git stash can pop directory/file saved changes' ' +test_expect_success 'git stash can pop directory/file saved changes' ' test_create_repo directory_file_switch_v2 && ( cd directory_file_switch_v2 &&