From 1e9d4284066dbb2307dfb9bb16121f57539d601f Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Sun, 14 Mar 2021 13:39:45 -0700 Subject: [PATCH] git: skip tags pointing to GPG keys and similar when importing refs --- lib/src/git.rs | 8 +++++++- lib/tests/test_git.rs | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/src/git.rs b/lib/src/git.rs index 642ab323a..787f47c6a 100644 --- a/lib/src/git.rs +++ b/lib/src/git.rs @@ -50,7 +50,13 @@ pub fn import_refs( // TODO: Is it useful to import HEAD (especially if it's detached)? continue; } - let git_commit = git_ref.peel_to_commit()?; + let git_commit = match git_ref.peel_to_commit() { + Ok(git_commit) => git_commit, + Err(_) => { + // Perhaps a tag pointing to a GPG key or similar. Just skip it. + continue; + } + }; let id = CommitId(git_commit.id().as_bytes().to_vec()); let commit = store.get_commit(&id).unwrap(); tx.add_head(&commit); diff --git a/lib/tests/test_git.rs b/lib/tests/test_git.rs index 4ed137f20..760cb4caa 100644 --- a/lib/tests/test_git.rs +++ b/lib/tests/test_git.rs @@ -110,6 +110,8 @@ fn test_import_refs_reimport() { let commit2 = empty_git_commit(&git_repo, "refs/heads/main", &[&commit1]); let commit3 = empty_git_commit(&git_repo, "refs/heads/feature1", &[&commit2]); let commit4 = empty_git_commit(&git_repo, "refs/heads/feature2", &[&commit2]); + let pgp_key_oid = git_repo.blob(b"my PGP key").unwrap(); + git_repo.reference("refs/tags/my-gpg-key", pgp_key_oid, false, "").unwrap(); let heads_before = repo.view().heads().clone(); let mut tx = repo.start_transaction("test");