fix: update_from_template.sh fails on first run#156
Merged
Conversation
Three bugs prevented the script from working correctly: 1. `git pull` after `git checkout -B` fails on a newly created branch with no upstream tracking, killing the script before the template merge ever executes (the critical bug). 2. `git remote add template` fails if the remote already exists from a previous crashed run, since cleanup at the end was never reached. 3. `git checkout --ours pixi.lock` errors when there is no merge conflict on that file. Also extract the template URL and branch name into variables to reduce duplication.
Reviewer's guide (collapsed on small PRs)Reviewer's GuideMakes the template update script robust on first and repeated runs by removing a failing pull on a new branch, making the template remote handling idempotent, guarding a conflict-resolution command, and extracting the template URL/branch into variables for reuse. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- Consider scoping
git config pull.rebase falseto the local repo (e.g.git config pull.rebase false) instead of using--global, to avoid surprising side effects on the developer's global Git configuration. - Since
TEMPLATE_URLandBRANCHare now variables, you may want to allow overriding them via environment variables (e.g.${TEMPLATE_URL:-default}) so the script can be reused with different templates/branches without editing the file.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider scoping `git config pull.rebase false` to the local repo (e.g. `git config pull.rebase false`) instead of using `--global`, to avoid surprising side effects on the developer's global Git configuration.
- Since `TEMPLATE_URL` and `BRANCH` are now variables, you may want to allow overriding them via environment variables (e.g. `${TEMPLATE_URL:-default}`) so the script can be reused with different templates/branches without editing the file.
## Individual Comments
### Comment 1
<location path="scripts/update_from_template.sh" line_range="7" />
<code_context>
+TEMPLATE_URL="https://github.com/blooop/python_template.git"
+BRANCH="feature/update_from_template"
+
git config --global pull.rebase false
-git remote add template https://github.com/blooop/python_template.git
+git remote remove template 2>/dev/null || true
</code_context>
<issue_to_address>
**issue (bug_risk):** Avoid mutating the user’s global git config from this script
Changing `~/.gitconfig` from a project script can unexpectedly affect all of the user’s repositories. Please restrict this setting to the local repo (e.g. `git config pull.rebase false` without `--global`) or require users to configure it themselves instead of forcing a global change.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
- Drop --global from `git config pull.rebase false` to avoid mutating
the user's global git configuration.
- Use ${VAR:-default} for TEMPLATE_URL and BRANCH so they can be
overridden via environment variables without editing the script.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
git pullaftergit checkout -B— on a newly created branch with no upstream,git pullfails andset -eo pipefailkills the script before the template merge ever runs. This was the root cause of the template history not being merged into downstream repos.templateremote before adding it, so re-runs after a crash don't fail atgit remote add.git checkout --ours pixi.lock— suppress errors when there's no merge conflict on that file.Test plan
scripts/update_from_template.sh— should complete and produce a merge commit with--allow-unrelated-histories🤖 Generated with Claude Code
Summary by Sourcery
Fix the template update script so it reliably creates and updates the template merge branch, even on first run against a repo with no shared history.
Bug Fixes:
Enhancements: