mirror of
https://codeberg.org/davrot/forgejo.git
synced 2025-05-16 11:00:02 +02:00
modules/git/repo_index.go aktualisiert
This commit is contained in:
parent
0e50e9dc10
commit
af19bf6c5b
1 changed files with 25 additions and 0 deletions
|
@ -6,6 +6,7 @@ package git
|
|||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
@ -102,6 +103,30 @@ func (repo *Repository) LsFiles(filenames ...string) ([]string, error) {
|
|||
return filelist, err
|
||||
}
|
||||
|
||||
// Gives a list of all files in a directory and below
|
||||
func (repo *Repository) LsFilesFromDirectory(directory, branch string) ([]string, error) {
|
||||
if branch == "" {
|
||||
return nil, errors.New("branch not found in context URL")
|
||||
}
|
||||
|
||||
cmd := NewCommand(repo.Ctx, "ls-files").AddDynamicArguments("--with-tree="+branch)
|
||||
if len(directory) > 0 {
|
||||
cmd = NewCommand(repo.Ctx, "ls-files").AddDynamicArguments("--with-tree="+branch).AddDynamicArguments("--directory").AddDynamicArguments(directory)
|
||||
}
|
||||
res, stderror, err := cmd.RunStdBytes(&RunOpts{Dir: repo.Path})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(stderror) > 0 {
|
||||
return nil, errors.New(string(stderror))
|
||||
}
|
||||
|
||||
lines := strings.Split(string(res), "\n")
|
||||
|
||||
return lines, nil
|
||||
}
|
||||
|
||||
// RemoveFilesFromIndex removes given filenames from the index - it does not check whether they are present.
|
||||
func (repo *Repository) RemoveFilesFromIndex(filenames ...string) error {
|
||||
objectFormat, err := repo.GetObjectFormat()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue