Repository: gogs/gogs
File: internal/database/repo_editor.go (Go)

Code before:
	LastCommitID string
	OldBranch    string
	NewBranch    string
	TreePath     string
	Message      string
}

func (r *Repository) DeleteRepoFile(doer *User, opts DeleteRepoFileOptions) (err error) {
	// 🚨 SECURITY: Prevent uploading files into the ".git" directory.
	if isRepositoryGitPath(opts.TreePath) {
		return errors.Errorf("bad tree path %q", opts.TreePath)
	}

	repoWorkingPool.CheckIn(com.ToStr(r.ID))
	defer repoWorkingPool.CheckOut(com.ToStr(r.ID))

	if err = r.DiscardLocalRepoBranchChanges(opts.OldBranch); err != nil {
		return fmt.Errorf("discard local r branch[%s] changes: %v", opts.OldBranch, err)
	} else if err = r.UpdateLocalCopyBranch(opts.OldBranch); err != nil {
		return fmt.Errorf("update local copy branch[%s]: %v", opts.OldBranch, err)
	}

	localPath := r.LocalCopyPath()

	// 🚨 SECURITY: Prevent touching files in surprising places, reject operations
	// involves symlinks.
	if hasSymlinkInPath(localPath, opts.TreePath) {
		return errors.New("cannot update file with symbolic link in path")
	}

	if opts.OldBranch != opts.NewBranch {
		if err := r.CheckoutNewBranch(opts.OldBranch, opts.NewBranch); err != nil {
			return fmt.Errorf("checkout new branch[%s] from old branch[%s]: %v", opts.NewBranch, opts.OldBranch, err)
		}
	}

	filePath := path.Join(localPath, opts.TreePath)
	if err = os.Remove(filePath); err != nil {
		return fmt.Errorf("remove file %q: %v", opts.TreePath, err)
	}

	if err = git.Add(localPath, git.AddOptions{All: true}); err != nil {
		return fmt.Errorf("git add --all: %v", err)
	}

	err = git.CreateCommit(
		localPath,
		&git.Signature{
			Name:  doer.DisplayName(),
			Email: doer.Email,
			When:  time.Now(),

Review comment (suggestion):
Grammar error in comment: "reject operations involves symlinks" should be "reject operations that involve symlinks" or "reject operations involving symlinks".
```suggestion
	// that involve symlinks.
```

Code after:
	LastCommitID string
	OldBranch    string
	NewBranch    string
	TreePath     string
	Message      string
}

func (r *Repository) DeleteRepoFile(doer *User, opts DeleteRepoFileOptions) (err error) {
	// 🚨 SECURITY: Prevent uploading files into the ".git" directory.
	if isRepositoryGitPath(opts.TreePath) {
		return errors.Errorf("bad tree path %q", opts.TreePath)
	}

	repoWorkingPool.CheckIn(com.ToStr(r.ID))
	defer repoWorkingPool.CheckOut(com.ToStr(r.ID))

	if err = r.DiscardLocalRepoBranchChanges(opts.OldBranch); err != nil {
		return fmt.Errorf("discard local r branch[%s] changes: %v", opts.OldBranch, err)
	} else if err = r.UpdateLocalCopyBranch(opts.OldBranch); err != nil {
		return fmt.Errorf("update local copy branch[%s]: %v", opts.OldBranch, err)
	}

	localPath := r.LocalCopyPath()

	// 🚨 SECURITY: Prevent touching files in surprising places, reject operations
	// that involve symlinks.
	if hasSymlinkInPath(localPath, opts.TreePath) {
		return errors.New("cannot update file with symbolic link in path")
	}

	if opts.OldBranch != opts.NewBranch {
		if err := r.CheckoutNewBranch(opts.OldBranch, opts.NewBranch); err != nil {
			return fmt.Errorf("checkout new branch[%s] from old branch[%s]: %v", opts.NewBranch, opts.OldBranch, err)
		}
	}

	filePath := path.Join(localPath, opts.TreePath)
	if err = os.Remove(filePath); err != nil {
		return fmt.Errorf("remove file %q: %v", opts.TreePath, err)
	}

	if err = git.Add(localPath, git.AddOptions{All: true}); err != nil {
		return fmt.Errorf("git add --all: %v", err)
	}

	err = git.CreateCommit(
		localPath,
		&git.Signature{
			Name:  doer.DisplayName(),
			Email: doer.Email,
			When:  time.Now(),