mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 02:46:04 +01:00 
			
		
		
		
	Allow custom default merge message with .gitea/default_merge_message/<merge_style>_TEMPLATE.md (#18177)
* Allow custom default merge message with .gitea/MERGE_MESSAGE_<merge_style>_TEMPLATE.md * Some improvements * Follow some advices * Fix bug * Fix bug * Fix lint * Fix close comment * Fix test * Fix and docs * Improve codes * Update docs and remove unnecessary variables * return error for GetDefaultMergeMessage * Fix test * improve code * ignore unknow unit type * return error for GetDefaultMergeMessage * Update services/pull/merge.go * Some improvements * Follow some advices * Fix bug * Fix lint * Improve codes * Update docs and remove unnecessary variables * return error for GetDefaultMergeMessage * improve code * Handle deleted HeadRepo in GetDefaultMergeMessage Signed-off-by: Andrew Thornton <art27@cantab.net> * Fix test * Fix test Co-authored-by: zeripath <art27@cantab.net>
This commit is contained in:
		| @@ -17,6 +17,7 @@ import ( | ||||
| 	"strings" | ||||
|  | ||||
| 	"code.gitea.io/gitea/modules/log" | ||||
| 	"code.gitea.io/gitea/modules/util" | ||||
| ) | ||||
|  | ||||
| // Commit represents a git commit. | ||||
| @@ -306,6 +307,35 @@ func (c *Commit) HasFile(filename string) (bool, error) { | ||||
| 	return true, nil | ||||
| } | ||||
|  | ||||
| // GetFileContent reads a file content as a string or returns false if this was not possible | ||||
| func (c *Commit) GetFileContent(filename string, limit int) (string, error) { | ||||
| 	entry, err := c.GetTreeEntryByPath(filename) | ||||
| 	if err != nil { | ||||
| 		return "", err | ||||
| 	} | ||||
|  | ||||
| 	r, err := entry.Blob().DataAsync() | ||||
| 	if err != nil { | ||||
| 		return "", err | ||||
| 	} | ||||
| 	defer r.Close() | ||||
|  | ||||
| 	if limit > 0 { | ||||
| 		bs := make([]byte, limit) | ||||
| 		n, err := util.ReadAtMost(r, bs) | ||||
| 		if err != nil { | ||||
| 			return "", err | ||||
| 		} | ||||
| 		return string(bs[:n]), nil | ||||
| 	} | ||||
|  | ||||
| 	bytes, err := io.ReadAll(r) | ||||
| 	if err != nil { | ||||
| 		return "", err | ||||
| 	} | ||||
| 	return string(bytes), nil | ||||
| } | ||||
|  | ||||
| // GetSubModules get all the sub modules of current revision git tree | ||||
| func (c *Commit) GetSubModules() (*ObjectCache, error) { | ||||
| 	if c.submoduleCache != nil { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user