Skip to content

Commit ce26178

Browse files
committed
refactor(lazygit): limit autosquash scan window
Keep the autosquash command's automatic oldest-target detection, but stop it from scanning arbitrarily deep history. Scan only the last 100 commits from HEAD when resolving fixup!/squash! commits, then rebase from the parent of the oldest matched target in that window. This preserves the existing behavior for recent work while avoiding huge rebases and unrelated conflicts in repositories that still contain older unsquashed fixup commits.
1 parent 1af2891 commit ce26178

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

modules/home/programs/terminal/tools/lazygit/custom-commands.nix

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
exit 1
2828
fi
2929
30+
maxScanCommits=100
31+
3032
workDir="''${TMPDIR:-/tmp}/lazygit-autosquash-$$"
3133
rm -rf "$workDir"
3234
mkdir -p "$workDir"
@@ -42,7 +44,7 @@
4244
: > "$orderFile"
4345
: > "$usedFile"
4446
45-
git --no-pager log --reverse --format='%H%x09%s' HEAD > "$historyFile"
47+
git --no-pager log --reverse -n "$maxScanCommits" --format='%H%x09%s' HEAD > "$historyFile"
4648
4749
fixupCount=0
4850
resolvedCount=0
@@ -84,12 +86,12 @@
8486
done < "$historyFile"
8587
8688
if [ "$fixupCount" -eq 0 ]; then
87-
echo "No fixup!/squash! commits found on this branch."
89+
echo "No fixup!/squash! commits found in the last $maxScanCommits commits."
8890
exit 1
8991
fi
9092
9193
if [ "$resolvedCount" -eq 0 ]; then
92-
echo "Found fixup!/squash! commits, but could not resolve target commits."
94+
echo "Found fixup!/squash! commits in the last $maxScanCommits commits, but none target commits in that window."
9395
exit 1
9496
fi
9597
@@ -121,15 +123,15 @@
121123
GIT_SEQUENCE_EDITOR=: git rebase -i --autosquash --no-verify --root
122124
fi
123125
'';
124-
description = "Autosquash all fixup/squash commits (auto-detect oldest target, skip hooks)";
126+
description = "Autosquash recent fixup/squash commits (last 100 commits)";
125127
loadingText = "Autosquashing fixup commits...";
126128
output = "log";
127129
prompts = [
128130
{
129131
type = "confirm";
130132
key = "ConfirmAutosquash";
131133
title = "Rewrite commit history?";
132-
body = "This auto-detects the oldest fixup target commit, rebases from its parent, and rewrites commit hashes.";
134+
body = "This searches the last 100 commits, rebases from the oldest fixup target it finds, and rewrites commit hashes.";
133135
}
134136
];
135137
}

0 commit comments

Comments
 (0)