Skip to content

Commit feddc78

Browse files
committed
fix(dotfiles): sanitize remote branch name before git reset --hard
Branch names resolved from git rev-parse or symbolic-ref (which may follow the network-supplied remote HEAD) are now rejected when they start with '-' or contain '..', both of which git would misparse as flags or path expressions. Falls back to 'main' in those cases.
1 parent d1efbd8 commit feddc78

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

internal/dotfiles/dotfiles.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ func Clone(repoURL string, dryRun bool) error {
9090
if branch == "" || branch == "HEAD" {
9191
branch = "main"
9292
}
93+
// Reject branch names that could be misinterpreted as flags or path
94+
// expressions by git — the remote HEAD ref comes from the network.
95+
if strings.HasPrefix(branch, "-") || strings.Contains(branch, "..") {
96+
branch = "main"
97+
}
9398
// Guard against silently discarding local uncommitted changes.
9499
if statusOut, err := exec.Command("git", "-C", dotfilesPath, "status", "--porcelain").Output(); err == nil && len(strings.TrimSpace(string(statusOut))) > 0 {
95100
ui.Warn(fmt.Sprintf("Local uncommitted changes detected in %s", dotfilesPath))

0 commit comments

Comments
 (0)