git-watchtower 2.1.7 → 2.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/git-watchtower.js +43 -6
- package/package.json +1 -1
package/bin/git-watchtower.js
CHANGED
|
@@ -1602,6 +1602,43 @@ async function undoLastSwitch() {
|
|
|
1602
1602
|
}
|
|
1603
1603
|
|
|
1604
1604
|
const lastSwitch = currentHistory[0];
|
|
1605
|
+
|
|
1606
|
+
// Detached HEAD restore: switchHistory captured the previous state as the
|
|
1607
|
+
// synthetic "HEAD@<hash>" name produced by getCurrentBranch(). sanitizeBranchName
|
|
1608
|
+
// rejects '@', so round-tripping through switchToBranch fails with "Invalid
|
|
1609
|
+
// Branch Name". Detect the detached form and `git checkout <hash>` directly.
|
|
1610
|
+
const detachedMatch = /^HEAD@([0-9a-f]{4,40})$/i.exec(lastSwitch.from);
|
|
1611
|
+
if (detachedMatch) {
|
|
1612
|
+
const hash = detachedMatch[1];
|
|
1613
|
+
addLog(`Undoing: restoring detached HEAD at ${hash}`, 'update');
|
|
1614
|
+
|
|
1615
|
+
if (await hasUncommittedChanges()) {
|
|
1616
|
+
addLog('Cannot undo: uncommitted changes in working directory', 'error');
|
|
1617
|
+
pendingDirtyOperation = { type: 'switch', branch: lastSwitch.from };
|
|
1618
|
+
showStashConfirm(`undo to detached HEAD ${hash}`);
|
|
1619
|
+
return { success: false, reason: 'dirty' };
|
|
1620
|
+
}
|
|
1621
|
+
|
|
1622
|
+
try {
|
|
1623
|
+
await execGit(['checkout', hash], { cwd: PROJECT_ROOT });
|
|
1624
|
+
store.setState({
|
|
1625
|
+
currentBranch: lastSwitch.from,
|
|
1626
|
+
isDetachedHead: true,
|
|
1627
|
+
switchHistory: store.get('switchHistory').slice(1),
|
|
1628
|
+
});
|
|
1629
|
+
addLog(`Undone: detached HEAD at ${hash}`, 'success');
|
|
1630
|
+
branchSwitchCount++;
|
|
1631
|
+
pendingDirtyOperation = null;
|
|
1632
|
+
notifyClients();
|
|
1633
|
+
return { success: true };
|
|
1634
|
+
} catch (e) {
|
|
1635
|
+
const errMsg = e.stderr || e.message || String(e);
|
|
1636
|
+
addLog(`Undo failed: ${errMsg}`, 'error');
|
|
1637
|
+
showErrorToast('Undo Failed', truncate(errMsg, 100), 'Commit may have been garbage-collected');
|
|
1638
|
+
return { success: false };
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
|
|
1605
1642
|
addLog(`Undoing: going back to ${lastSwitch.from}`, 'update');
|
|
1606
1643
|
|
|
1607
1644
|
const result = await switchToBranch(lastSwitch.from, false);
|
|
@@ -3125,12 +3162,12 @@ async function handleWebAction(action, payload) {
|
|
|
3125
3162
|
sendResult(true, 'Fetch complete');
|
|
3126
3163
|
break;
|
|
3127
3164
|
case 'undo': {
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
sendResult(true, `
|
|
3165
|
+
// Delegate to undoLastSwitch so detached-HEAD restoration and
|
|
3166
|
+
// history popping stay consistent with the TUI 'u' keybinding.
|
|
3167
|
+
const result = await undoLastSwitch();
|
|
3168
|
+
await pollGitChanges();
|
|
3169
|
+
if (result.success) {
|
|
3170
|
+
sendResult(true, `Undone last switch`);
|
|
3134
3171
|
} else {
|
|
3135
3172
|
sendResult(false, 'No switch to undo');
|
|
3136
3173
|
}
|
package/package.json
CHANGED