Skip to content

Commit 764f1ad

Browse files
committed
feat(dc-init): amend existing dc-init commits instead of stacking duplicates
When rerunning batch mode (--update or --batch), detect if HEAD is already a chore(dc-init): commit and amend it with date preservation + force-push-with-lease (gcda-style) instead of creating a new commit.
1 parent 4bd6d3d commit 764f1ad

File tree

1 file changed

+40
-12
lines changed

1 file changed

+40
-12
lines changed

scripts/template-loading.sh

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,12 +1474,26 @@ run_batch_update() {
14741474
done
14751475

14761476
if ! git diff --cached --quiet; then
1477-
git commit -m "chore(dc-init): update ${choice_desc}" --quiet
1478-
print_success "Committed template updates for $d"
1479-
1480-
if git remote get-url origin &>/dev/null; then
1481-
if ! git push origin "$current_branch" --quiet 2>/dev/null; then
1482-
print_warning "Push failed for $d (changes committed locally)"
1477+
# If the last commit was already a dc-init commit, amend it (gcda-style)
1478+
local last_msg
1479+
last_msg=$(git log -1 --format=%s 2>/dev/null || echo "")
1480+
if [[ "$last_msg" == chore\(dc-init\):* ]]; then
1481+
local author_date
1482+
author_date=$(git show -s --format=%aD HEAD)
1483+
GIT_COMMITTER_DATE="$author_date" git commit --amend --no-edit --date="$author_date" --quiet
1484+
print_success "Amended dc-init commit for $d"
1485+
if git remote get-url origin &>/dev/null; then
1486+
if ! git push --force-with-lease origin "$current_branch" --quiet 2>/dev/null; then
1487+
print_warning "Force-push failed for $d (amended locally)"
1488+
fi
1489+
fi
1490+
else
1491+
git commit -m "chore(dc-init): update ${choice_desc}" --quiet
1492+
print_success "Committed template updates for $d"
1493+
if git remote get-url origin &>/dev/null; then
1494+
if ! git push origin "$current_branch" --quiet 2>/dev/null; then
1495+
print_warning "Push failed for $d (changes committed locally)"
1496+
fi
14831497
fi
14841498
fi
14851499
((updated++)) || true
@@ -1825,12 +1839,26 @@ run_batch_init() {
18251839
local choice_desc
18261840
choice_desc=$(describe_template_choices "${SELECTED_TEMPLATE_CHOICES}")
18271841
git add -A
1828-
git commit -m "chore(dc-init): load ${choice_desc}" --quiet
1829-
print_success "Committed template changes for $d"
1830-
1831-
if git remote get-url origin &>/dev/null; then
1832-
if ! git push origin "$current_branch" --quiet 2>/dev/null; then
1833-
print_warning "Push failed for $d (changes committed locally)"
1842+
# If the last commit was already a dc-init commit, amend it (gcda-style)
1843+
local last_msg
1844+
last_msg=$(git log -1 --format=%s 2>/dev/null || echo "")
1845+
if [[ "$last_msg" == chore\(dc-init\):* ]]; then
1846+
local author_date
1847+
author_date=$(git show -s --format=%aD HEAD)
1848+
GIT_COMMITTER_DATE="$author_date" git commit --amend --no-edit --date="$author_date" --quiet
1849+
print_success "Amended dc-init commit for $d"
1850+
if git remote get-url origin &>/dev/null; then
1851+
if ! git push --force-with-lease origin "$current_branch" --quiet 2>/dev/null; then
1852+
print_warning "Force-push failed for $d (amended locally)"
1853+
fi
1854+
fi
1855+
else
1856+
git commit -m "chore(dc-init): load ${choice_desc}" --quiet
1857+
print_success "Committed template changes for $d"
1858+
if git remote get-url origin &>/dev/null; then
1859+
if ! git push origin "$current_branch" --quiet 2>/dev/null; then
1860+
print_warning "Push failed for $d (changes committed locally)"
1861+
fi
18341862
fi
18351863
fi
18361864
fi

0 commit comments

Comments
 (0)