git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Ivan Tse via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Ivan Tse <ivan.tse1@gmail.com>, Ivan Tse <ivan.tse1@gmail.com>
Subject: [PATCH] refs: return conflict error when checking packed refs
Date: Tue, 30 Apr 2024 14:50:47 +0000	[thread overview]
Message-ID: <pull.1716.git.git.1714488648294.gitgitgadget@gmail.com> (raw)

From: Ivan Tse <ivan.tse1@gmail.com>

The TRANSACTION_NAME_CONFLICT error code refers to a failure to create a
ref due to a name conflict with another ref. An example of this is a
directory/file conflict such as ref names A/B and A.

"git fetch" uses this error code to more accurately describe the error
by recommending to the user that they try running "git remote prune" to
remove any old refs that are deleted by the remote which would clear up
any directory/file conflicts.

This helpful error message is not displayed when the conflicted ref is
stored in packed refs. This change fixes this by ensuring error return
code consistency in `lock_raw_ref`.

Signed-off-by: Ivan Tse <ivan.tse1@gmail.com>
---
    refs: return conflict error when checking packed refs
    
    I wanted to provide extra context around the error message I'm referring
    to so it's clear what I'm trying to achieve.
    
    First, let's get into a directory/file conflict situation:
    
    git branch dir_file_conflict
    git push origin dir_file_conflict
    git update-ref -d refs/remotes/origin/dir_file_conflict
    git update-ref -d refs/heads/dir_file_conflict
    git update-ref refs/remotes/origin/dir_file_conflict/file master
    
    
    From above, the remote origin has a dir_file_conflict ref name and the
    local repository has a dir_file_conflict/file ref name for the remote.
    This situation can occur if dir_file_conflict/file used to exist and but
    was later deleted in the remote.
    
    Then when we git fetch:
    
    yolo10[master] $ git fetch
    error: cannot lock ref 'refs/remotes/origin/dir_file_conflict': 'refs/remotes/origin/dir_file_conflict/file' exists; cannot create 'refs/remotes/origin/dir_file_conflict'
    From github.com:ivantsepp/yolo10
     ! [new branch]      dir_file_conflict -> origin/dir_file_conflict  (unable to update local ref)
    error: some local refs could not be updated; try running
     'git remote prune origin' to remove any old, conflicting branches
    
    
    We get the helpful error message to run git remote prune origin to
    remove old, conflicting branches.
    
    However, when the ref is stored in packed refs:
    
    yolo10[master] $ git pack-refs --all
    yolo10[master] $ git fetch
    error: cannot lock ref 'refs/remotes/origin/dir_file_conflict': 'refs/remotes/origin/dir_file_conflict/file' exists; cannot create 'refs/remotes/origin/dir_file_conflict'
    From github.com:ivantsepp/yolo10
     ! [new branch]      dir_file_conflict -> origin/dir_file_conflict  (unable to update local ref)
    
    
    The helpful message is not there! I believe this error message should
    show up regardless of how the ref is stored (loose vs packed-refs). I
    attempted to track down the necessary change to make this happen and it
    seems like a straightforward change. I hope I didn't overlook anything!

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1716%2Fivantsepp%2Freturn_name_conflict_error_for_packed_refs-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1716/ivantsepp/return_name_conflict_error_for_packed_refs-v1
Pull-Request: https://github.com/git/git/pull/1716

 refs/files-backend.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/refs/files-backend.c b/refs/files-backend.c
index a098d14ea00..97473f377d1 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -794,8 +794,10 @@ static int lock_raw_ref(struct files_ref_store *refs,
 		 */
 		if (refs_verify_refname_available(
 				    refs->packed_ref_store, refname,
-				    extras, NULL, err))
+				    extras, NULL, err)) {
+			ret = TRANSACTION_NAME_CONFLICT;
 			goto error_return;
+		}
 	}
 
 	ret = 0;

base-commit: 786a3e4b8d754d2b14b1208b98eeb0a554ef19a8
-- 
gitgitgadget


             reply	other threads:[~2024-04-30 14:51 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-30 14:50 Ivan Tse via GitGitGadget [this message]
2024-05-02 12:38 ` [PATCH] refs: return conflict error when checking packed refs Patrick Steinhardt
2024-05-03  4:50 ` [PATCH v2] " Ivan Tse via GitGitGadget
2024-05-03  6:38   ` Patrick Steinhardt
2024-05-04  3:04   ` [PATCH v3] " Ivan Tse via GitGitGadget
2024-05-06  6:47     ` Patrick Steinhardt
2024-05-06 11:40     ` Karthik Nayak
2024-05-06 19:01       ` Junio C Hamano
2024-05-07  5:51         ` Ivan Tse
2024-05-07 13:37           ` Karthik Nayak
2024-05-08  1:39             ` Ivan Tse

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=pull.1716.git.git.1714488648294.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=ivan.tse1@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).