Skip to content

Commit eb5b319

Browse files
Merge pull request #1049 from stoneshi-yunify/master
fix git operation
2 parents da39d06 + 6dec1f5 commit eb5b319

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

Diff for: pkg/kapis/devops/v1alpha3/gitops/git.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ func (s *gitRepoService) ListBranches(ctx context.Context, input *ListBranchesIn
737737
hash = head.Hash()
738738
}
739739
commit, err := s.repo.CommitObject(hash)
740-
if err != nil {
740+
if err != nil && !errors.Is(err, plumbing.ErrObjectNotFound) {
741741
return nil, err
742742
}
743743
branch := &BranchInfo{
@@ -851,6 +851,15 @@ func (s *gitRepoService) AddFiles(ctx context.Context, input *AddFilesInput) (*A
851851
if err == nil && !input.Overwrite {
852852
continue
853853
}
854+
855+
if len(file.OldName) > 0 {
856+
oldFilePath := w.Filesystem.Join(root, file.OldName)
857+
err = os.RemoveAll(oldFilePath)
858+
if err != nil {
859+
return nil, err
860+
}
861+
}
862+
854863
filePath := w.Filesystem.Join(root, file.Name)
855864
err = os.RemoveAll(filePath)
856865
if err != nil {

Diff for: pkg/kapis/devops/v1alpha3/gitops/types.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,9 @@ type BranchInfo struct {
112112
type ListBranchesOutput ListResult[*BranchInfo]
113113

114114
type FileNameData struct {
115-
Data []byte `json:"data"`
116-
Name string `json:"name"`
115+
Data []byte `json:"data"` // NOTE: empty file is valid!
116+
Name string `json:"name"`
117+
OldName string `json:"oldName"` // used when move/rename a file
117118
}
118119

119120
type FileInfo struct {

0 commit comments

Comments
 (0)