Skip to content

Commit da047d8

Browse files
committed
feat(aicommit): Add --pull flag for auto-pull
- Introduces the `--pull` flag to `aicommit`. - Allows the script to automatically pull the current branch from `origin` with `--no-rebase` before generating the commit. - Ensures that commits are based on the latest remote state, preventing stale commits.
1 parent 329151c commit da047d8

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

.codesync-todos.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"todos": [
3+
{
4+
"content": "Add --pull flag to usage header comment",
5+
"status": "completed",
6+
"active_form": "Adding --pull flag to usage header comment",
7+
"created_at": "2026-05-03T20:13:20.881753Z",
8+
"updated_at": "2026-05-03T20:14:11.209546Z"
9+
},
10+
{
11+
"content": "Add --pull flag to show_help function",
12+
"status": "completed",
13+
"active_form": "Adding --pull flag to show_help function",
14+
"created_at": "2026-05-03T20:13:20.881753Z",
15+
"updated_at": "2026-05-03T20:14:11.209546Z"
16+
},
17+
{
18+
"content": "Add AUTO_PULL variable and argument parsing",
19+
"status": "completed",
20+
"active_form": "Adding AUTO_PULL variable and argument parsing",
21+
"created_at": "2026-05-03T20:13:20.881753Z",
22+
"updated_at": "2026-05-03T20:14:11.209546Z"
23+
},
24+
{
25+
"content": "Add git pull --no-rebase logic before commit",
26+
"status": "completed",
27+
"active_form": "Adding git pull --no-rebase logic before commit",
28+
"created_at": "2026-05-03T20:13:20.881753Z",
29+
"updated_at": "2026-05-03T20:14:11.209546Z"
30+
}
31+
],
32+
"updated_at": "2026-05-03T20:14:11.209546Z"
33+
}

aicommit

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# aicommit -y|--yes # non-interactive; auto-use generated message
1515
# aicommit -p|--provider <name> # use a specific AI provider
1616
# aicommit -m|--model <name> # optional model override for the chosen provider
17+
# aicommit --pull # auto pull origin branch with --no-rebase before commit
1718
# aicommit -r|--release [bump|ver] # release: patch, minor, major, X.Y.Z, or auto
1819
# aicommit -h|--help # show this help
1920
# aicommit -v|-V|--version # show version information
@@ -87,6 +88,7 @@ show_help() {
8788
echo -e " ${C_GREEN}--no-push${C_RESET}, ${C_GREEN}-n${C_RESET} Do not push the commit to the remote."
8889
echo -e " ${C_GREEN}--yes${C_RESET}, ${C_GREEN}-y${C_RESET} Assume yes: auto-use the generated message."
8990
echo -e " ${C_GREEN}--changelog${C_RESET}, ${C_GREEN}-c${C_RESET} Update CHANGELOG.md with this commit."
91+
echo -e " ${C_GREEN}--pull${C_RESET} Auto pull from origin with --no-rebase before committing."
9092
echo -e " ${C_GREEN}--release${C_RESET}, ${C_GREEN}-r${C_RESET} ${C_DIM}[type]${C_RESET} Create a release. Type: patch, minor, major, or X.Y.Z."
9193
echo -e " ${C_DIM}If omitted, AI auto-detects the bump type.${C_RESET}"
9294
echo -e " ${C_GREEN}-v${C_RESET}, ${C_GREEN}-V${C_RESET}, ${C_GREEN}--version${C_RESET} Show version information."
@@ -209,13 +211,15 @@ ASSUME_YES=false
209211
UPDATE_CHANGELOG=false
210212
CLI_PROVIDER=""
211213
CLI_MODEL=""
214+
AUTO_PULL=false
212215
RELEASE_MODE=false
213216
RELEASE_ARG=""
214217

215218
while (( "$#" )); do
216219
case "$1" in
217220
--no-push|-n) NO_PUSH=true ;;
218221
--yes|-y) ASSUME_YES=true ;;
222+
--pull) AUTO_PULL=true ;;
219223
--changelog|-c) UPDATE_CHANGELOG=true ;;
220224
--provider|-p)
221225
shift
@@ -1443,6 +1447,18 @@ if ! $ASSUME_YES; then
14431447
read -p "Press Enter to commit (Ctrl+C to abort) … "
14441448
fi
14451449

1450+
# ---- Auto pull (if requested) ----
1451+
if $AUTO_PULL; then
1452+
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
1453+
echo "Pulling from origin/$CURRENT_BRANCH with --no-rebase..."
1454+
if git pull --no-rebase origin "$CURRENT_BRANCH"; then
1455+
echo "✅ Pull completed successfully."
1456+
else
1457+
echo "⚠️ Pull failed. Please resolve conflicts and try again."
1458+
exit 1
1459+
fi
1460+
fi
1461+
14461462
# ---- Commit ----
14471463
git add -A
14481464
git commit -m "$FINAL_MSG"

0 commit comments

Comments
 (0)