mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	Change the implementation of the go-git version of GetNote to mirror the non go-git version when passed a non-existent commit (#16658)
Fixes #16657
This commit is contained in:
		@@ -36,6 +36,9 @@ func GetNote(ctx context.Context, repo *Repository, commitID string, note *Note)
 | 
				
			|||||||
			remainingCommitID = remainingCommitID[2:]
 | 
								remainingCommitID = remainingCommitID[2:]
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
 | 
								if err == object.ErrDirectoryNotFound {
 | 
				
			||||||
 | 
									return ErrNotExist{ID: remainingCommitID, RelPath: path}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
			return err
 | 
								return err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -39,3 +39,15 @@ func TestGetNestedNotes(t *testing.T) {
 | 
				
			|||||||
	assert.NoError(t, err)
 | 
						assert.NoError(t, err)
 | 
				
			||||||
	assert.Equal(t, []byte("Note 1"), note.Message)
 | 
						assert.Equal(t, []byte("Note 1"), note.Message)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestGetNonExistentNotes(t *testing.T) {
 | 
				
			||||||
 | 
						bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
 | 
				
			||||||
 | 
						bareRepo1, err := OpenRepository(bareRepo1Path)
 | 
				
			||||||
 | 
						assert.NoError(t, err)
 | 
				
			||||||
 | 
						defer bareRepo1.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						note := Note{}
 | 
				
			||||||
 | 
						err = GetNote(context.Background(), bareRepo1, "non_existent_sha", ¬e)
 | 
				
			||||||
 | 
						assert.Error(t, err)
 | 
				
			||||||
 | 
						assert.IsType(t, ErrNotExist{}, err)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user