// CommitChanges commits some changes into a branch.
CommitChanges commits some changes into a branch.
// CommitChanges commits some changes into a branch .
func (r *repo) CommitChanges(ctx context.Context, branch, message string, newBranch bool, changes map[string][]byte) error {
	if newBranch {
		if err := r.checkoutNewBranch(ctx, branch); err != nil {
			return fmt.Errorf("failed to checkout new branch, branch: %v, error: %v", branch, err)
		}
	} else {
		if err := r.Checkout(ctx, branch); err != nil {
			return fmt.Errorf("failed to checkout branch, branch: %v, error: %v", branch, err)
		}
	}
	for p, bytes := range changes {
		filePath := filepath.Join(r.dir, p)
		dirPath := filepath.Dir(filePath)
		if _, err := os.Stat(dirPath); os.IsNotExist(err) {
			if err := os.MkdirAll(dirPath, os.ModePerm); err != nil {
				return fmt.Errorf("failed to create directory, dir: %s, err: %v", dirPath, err)
			}
		}
		if err := os.WriteFile(filePath, bytes, os.ModePerm); err != nil {
			return fmt.Errorf("failed to write file, file: %s, error: %v", filePath, err)
		}
	}
	if err := r.addCommit(ctx, message); err != nil {
		return fmt.Errorf("failed to commit, branch: %s, error: %v", branch, err)
	}
	return nil
}
func ( r * repo ) CommitChanges ( ctx context . Context , branch , message string , newBranch bool , changes map [ string ] [ ] byte ) error { if newBranch { if err := r . checkoutNewBranch ( ctx , branch ) ; err != nil { return fmt . Errorf ( " " , branch , err ) } } else { if err := r . Checkout ( ctx , branch ) ; err != nil { return fmt . Errorf ( " " , branch , err ) } } for p , bytes := range changes { filePath := filepath . Join ( r . dir , p ) dirPath := filepath . Dir ( filePath ) if _ , err := os . Stat ( dirPath ) ; os . IsNotExist ( err ) { if err := os . MkdirAll ( dirPath , os . ModePerm ) ; err != nil { return fmt . Errorf ( " " , dirPath , err ) } } if err := os . WriteFile ( filePath , bytes , os . ModePerm ) ; err != nil { return fmt . Errorf ( " " , filePath , err ) } } if err := r . addCommit ( ctx , message ) ; err != nil { return fmt . Errorf ( " " , branch , err ) } return nil }
CommitChanges commits some changes into a branch.
CommitChanges commits some changes into a branch .
// Apply the changes. // Commit the changes.