mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-26 12:27:06 +00:00 
			
		
		
		
	Fix parentCommit invalid memory address or nil pointer dereference. (#33204)
When the parent Commit does not exist on gitea, an error will be reported when opening the Commit details page: invalid memory address or nil pointer dereference.  
This commit is contained in:
		| @@ -64,7 +64,10 @@ func GetRepoRawDiffForFile(repo *Repository, startCommit, endCommit string, diff | |||||||
| 		} else if commit.ParentCount() == 0 { | 		} else if commit.ParentCount() == 0 { | ||||||
| 			cmd.AddArguments("show").AddDynamicArguments(endCommit).AddDashesAndList(files...) | 			cmd.AddArguments("show").AddDynamicArguments(endCommit).AddDashesAndList(files...) | ||||||
| 		} else { | 		} else { | ||||||
| 			c, _ := commit.Parent(0) | 			c, err := commit.Parent(0) | ||||||
|  | 			if err != nil { | ||||||
|  | 				return err | ||||||
|  | 			} | ||||||
| 			cmd.AddArguments("diff", "-M").AddDynamicArguments(c.ID.String(), endCommit).AddDashesAndList(files...) | 			cmd.AddArguments("diff", "-M").AddDynamicArguments(c.ID.String(), endCommit).AddDashesAndList(files...) | ||||||
| 		} | 		} | ||||||
| 	case RawDiffPatch: | 	case RawDiffPatch: | ||||||
| @@ -74,7 +77,10 @@ func GetRepoRawDiffForFile(repo *Repository, startCommit, endCommit string, diff | |||||||
| 		} else if commit.ParentCount() == 0 { | 		} else if commit.ParentCount() == 0 { | ||||||
| 			cmd.AddArguments("format-patch", "--no-signature", "--stdout", "--root").AddDynamicArguments(endCommit).AddDashesAndList(files...) | 			cmd.AddArguments("format-patch", "--no-signature", "--stdout", "--root").AddDynamicArguments(endCommit).AddDashesAndList(files...) | ||||||
| 		} else { | 		} else { | ||||||
| 			c, _ := commit.Parent(0) | 			c, err := commit.Parent(0) | ||||||
|  | 			if err != nil { | ||||||
|  | 				return err | ||||||
|  | 			} | ||||||
| 			query := fmt.Sprintf("%s...%s", endCommit, c.ID.String()) | 			query := fmt.Sprintf("%s...%s", endCommit, c.ID.String()) | ||||||
| 			cmd.AddArguments("format-patch", "--no-signature", "--stdout").AddDynamicArguments(query).AddDashesAndList(files...) | 			cmd.AddArguments("format-patch", "--no-signature", "--stdout").AddDynamicArguments(query).AddDashesAndList(files...) | ||||||
| 		} | 		} | ||||||
|   | |||||||
| @@ -1136,7 +1136,10 @@ func GetDiff(ctx context.Context, gitRepo *git.Repository, opts *DiffOptions, fi | |||||||
| 	} else { | 	} else { | ||||||
| 		actualBeforeCommitID := opts.BeforeCommitID | 		actualBeforeCommitID := opts.BeforeCommitID | ||||||
| 		if len(actualBeforeCommitID) == 0 { | 		if len(actualBeforeCommitID) == 0 { | ||||||
| 			parentCommit, _ := commit.Parent(0) | 			parentCommit, err := commit.Parent(0) | ||||||
|  | 			if err != nil { | ||||||
|  | 				return nil, err | ||||||
|  | 			} | ||||||
| 			actualBeforeCommitID = parentCommit.ID.String() | 			actualBeforeCommitID = parentCommit.ID.String() | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| @@ -1145,7 +1148,6 @@ func GetDiff(ctx context.Context, gitRepo *git.Repository, opts *DiffOptions, fi | |||||||
| 			AddDynamicArguments(actualBeforeCommitID, opts.AfterCommitID) | 			AddDynamicArguments(actualBeforeCommitID, opts.AfterCommitID) | ||||||
| 		opts.BeforeCommitID = actualBeforeCommitID | 		opts.BeforeCommitID = actualBeforeCommitID | ||||||
|  |  | ||||||
| 		var err error |  | ||||||
| 		beforeCommit, err = gitRepo.GetCommit(opts.BeforeCommitID) | 		beforeCommit, err = gitRepo.GetCommit(opts.BeforeCommitID) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return nil, err | 			return nil, err | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 hiifong
					hiifong