MCPcopy Create free account
hub / github.com/github/gh-aw / RollbackModifiedFiles

Method RollbackModifiedFiles

pkg/cli/file_tracker.go:151–180  ·  view source on GitHub ↗

RollbackModifiedFiles restores all modified files to their original state

(verbose bool)

Source from the content-addressed store, hash-verified

149
150// RollbackModifiedFiles restores all modified files to their original state
151func (ft *FileTracker) RollbackModifiedFiles(verbose bool) error {
152 if len(ft.ModifiedFiles) == 0 {
153 return nil
154 }
155
156 console.LogVerbose(verbose, fmt.Sprintf("Rolling back %d modified files...", len(ft.ModifiedFiles)))
157
158 var errors []string
159 for _, file := range ft.ModifiedFiles {
160 console.LogVerbose(verbose, " - Restoring "+file)
161
162 // Restore original content if we have it
163 if originalContent, exists := ft.OriginalContent[file]; exists {
164 // Use owner-only read/write permissions (0600) for security best practices
165 if err := os.WriteFile(file, originalContent, constants.FilePermSensitive); err != nil {
166 errors = append(errors, fmt.Sprintf("failed to restore %s: %v", file, err))
167 }
168 } else {
169 if verbose {
170 fmt.Fprintln(os.Stderr, console.FormatWarningMessage("No original content stored for "+file))
171 }
172 }
173 }
174
175 if len(errors) > 0 {
176 return fmt.Errorf("rollback errors: %s", strings.Join(errors, "; "))
177 }
178
179 return nil
180}
181
182// RollbackAllFiles rolls back both created and modified files
183func (ft *FileTracker) RollbackAllFiles(verbose bool) error {

Callers 2

RollbackAllFilesMethod · 0.95

Calls 3

LogVerboseFunction · 0.92
FormatWarningMessageFunction · 0.92
ErrorfMethod · 0.45

Tested by 1