From fd85d31cb4a01cb7fdf77f78342bc417bc802cdf Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 5 Mar 2020 16:55:21 +0800 Subject: [PATCH] Ensure executable bit is kept on the web editor (#10607) (#10614) Co-authored-by: Antoine GIRARD Co-authored-by: Antoine GIRARD --- modules/repofiles/update.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/modules/repofiles/update.go b/modules/repofiles/update.go index 32a5c5297b..02bd318917 100644 --- a/modules/repofiles/update.go +++ b/modules/repofiles/update.go @@ -210,6 +210,7 @@ func CreateOrUpdateRepoFile(repo *models.Repository, doer *models.User, opts *Up encoding := "UTF-8" bom := false + executable := false if !opts.IsNewFile { fromEntry, err := commit.GetTreeEntryByPath(fromTreePath) @@ -245,6 +246,7 @@ func CreateOrUpdateRepoFile(repo *models.Repository, doer *models.User, opts *Up return nil, models.ErrSHAOrCommitIDNotProvided{} } encoding, bom = detectEncodingAndBOM(fromEntry, repo) + executable = fromEntry.IsExecutable() } // For the path where this file will be created/updated, we need to make @@ -368,8 +370,14 @@ func CreateOrUpdateRepoFile(repo *models.Repository, doer *models.User, opts *Up } // Add the object to the index - if err := t.AddObjectToIndex("100644", objectHash, treePath); err != nil { - return nil, err + if executable { + if err := t.AddObjectToIndex("100755", objectHash, treePath); err != nil { + return nil, err + } + } else { + if err := t.AddObjectToIndex("100644", objectHash, treePath); err != nil { + return nil, err + } } // Now write the tree