Skip to content

Use git -C Folder command instead of pushd Folder / git command#2419

Merged
CLHatch merged 1 commit intomainfrom
git
Jan 26, 2026
Merged

Use git -C Folder command instead of pushd Folder / git command#2419
CLHatch merged 1 commit intomainfrom
git

Conversation

@CLHatch
Copy link
Contributor

@CLHatch CLHatch commented Jan 26, 2026

… / popd

Pull request

Purpose
Describe the problem or feature in addition to a link to the issues.

Approach
How does this change address the problem?

Open Questions and Pre-Merge TODOs
Check all boxes as they are completed

  • Use github checklists. When solved, check the box and explain the answer.

Learning
Describe the research stage
Links to blog posts, patterns, libraries or addons used to solve this problem

Requirements
Check all boxes as they are completed

Summary by Sourcery

Replace directory-changing git invocations with path-scoped git commands and improve update workflows’ robustness.

Enhancements:

  • Use git -C <path> instead of pushd/popd around git commands across shared git helper functions.
  • Simplify and harden self-update and template-update scripts by removing explicit directory stack management and running git operations directly against known paths.
  • Route git garbage collection and ownership-fix steps through existing logging helpers for clearer, more consistent output.
  • Ensure update commands for app and templates are tolerant of failures by not aborting the overall command when individual updates fail.

@CLHatch CLHatch requested a review from a team as a code owner January 26, 2026 05:12
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jan 26, 2026

Reviewer's Guide

Refactors Git interactions in shell scripts to use git -C <path> instead of directory stack manipulation, simplifies directory handling in self-update/template-update flows, and aligns Git commands with centralized logging while making update subcommands more fault-tolerant.

Sequence diagram for the updated fault-tolerant update command flow

sequenceDiagram
  actor User
  participant CLI as dockstarter_cli
  participant CmdHandler as run_command
  participant UpdateTemplates as update_templates
  participant UpdateSelf as update_self
  participant Git as git

  User->>CLI: run with --update AppBranch TemplatesBranch
  CLI->>CmdHandler: run_command --update
  CmdHandler->>UpdateTemplates: run_script update_templates TemplatesBranch
  Note over UpdateTemplates,CmdHandler: update_templates may fail but is wrapped with || true
  UpdateTemplates->>Git: git -C TEMPLATES_PARENT_FOLDER fetch/checkout/reset/pull/gc
  UpdateTemplates-->>CmdHandler: success or failure (ignored)

  CmdHandler->>UpdateSelf: run_script update_self AppBranch REST_OF_ARGS
  Note over UpdateSelf,CmdHandler: update_self may fail but is wrapped with || true
  UpdateSelf->>Git: git -C SCRIPTPATH fetch/checkout/reset/pull/gc
  UpdateSelf-->>CmdHandler: success or failure (ignored)

  CmdHandler-->>CLI: result (last command status)
  CLI-->>User: prints update notices and completion status
Loading

File-Level Changes

Change Details Files
Replace pushd/popd-based directory changes with path-scoped git invocations in shared git helper functions.
  • Remove use of pushd/popd in git helper functions that operate on a target repository path.
  • Update git fetch, branch/tag/commit existence checks, ref resolution, and describe/rev-parse calls to use git -C "${GitPath}" ....
  • Adjust git_best_branch to query remote branches via git -C "${GitPath}" branch -r --contains HEAD and to use git -C for show-ref when verifying the default branch.
.includes/ds_functions.sh
Simplify update_self workflow by removing explicit directory stack management and scoping all git operations to SCRIPTPATH.
  • Remove RunAndLog-wrapped pushd/popd around ${SCRIPTPATH} in update_self and commands_update_self_logic.
  • Update ownership-fix commands that relied on current directory to use git -C "${SCRIPTPATH}" ls-tree ....
  • Change git fetch/checkout/reset/pull/gc to run via git -C "${SCRIPTPATH}" and route gc through RunAndLog for consistent logging.
  • Split ownership adjustment of new files into explicit sudo chown calls rather than embedding inside info message interpolation.
.scripts/update_self.sh
Simplify update_templates workflow by removing directory stack manipulation and scoping git operations to TEMPLATES_PARENT_FOLDER.
  • Remove RunAndLog-wrapped pushd/popd around ${TEMPLATES_PARENT_FOLDER} in update_templates and commands_update_templates.
  • Update ownership-fix commands that relied on current directory to use git -C "${TEMPLATES_PARENT_FOLDER}" ls-tree ....
  • Change git fetch/checkout/reset/pull/gc to run via git -C "${TEMPLATES_PARENT_FOLDER}" and send gc through RunAndLog for consistent logging.
  • Keep reset_needs script invocation but remove trailing comment and redundant popd cleanup.
.scripts/update_templates.sh
Make combined update command more resilient to failures in individual update steps.
  • Wrap calls to update_templates and update_self in run_command's --update handler with `

Possibly linked issues

  • #(unknown): PR updates git calls and update flow, likely resolving the ds -u git error causing Dockstarter commands to fail.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@github-actions github-actions bot added the core Automatic label label Jan 26, 2026
@CLHatch CLHatch merged commit d2b2c2e into main Jan 26, 2026
16 checks passed
@CLHatch CLHatch deleted the git branch January 26, 2026 05:12
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 2 issues, and left some high level feedback:

  • In commands_update_self_logic and commands_update_templates, the new RunAndLog ... git -C ... gc || true usage will pass '||' and 'true' as literal arguments to git rather than short‑circuiting in the shell; consider either dropping || true (and letting RunAndLog handle failures) or wrapping the command in a subshell (e.g. bash -c 'git -C ... gc || true').
  • The changes in run_command to append || true to run_script 'update_templates' and run_script 'update_self' will now ignore failures from those update routines; please confirm whether this is intentional, and if not, propagate or handle the errors explicitly instead of masking them.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `commands_update_self_logic` and `commands_update_templates`, the new `RunAndLog ... git -C ... gc || true` usage will pass `'||'` and `'true'` as literal arguments to `git` rather than short‑circuiting in the shell; consider either dropping `|| true` (and letting `RunAndLog` handle failures) or wrapping the command in a subshell (e.g. `bash -c 'git -C ... gc || true'`).
- The changes in `run_command` to append `|| true` to `run_script 'update_templates'` and `run_script 'update_self'` will now ignore failures from those update routines; please confirm whether this is intentional, and if not, propagate or handle the errors explicitly instead of masking them.

## Individual Comments

### Comment 1
<location> `.includes/ds_functions.sh:9-10` </location>
<code_context>
-	git fetch --quiet --tags &> /dev/null || true
-	git symbolic-ref --short HEAD 2> /dev/null || git describe --tags --exact-match 2> /dev/null || git_best_branch "${GitPath}" "${DefaultBranch-}" "${LegacyBranch-}"
-	popd &> /dev/null
+	git -C "${GitPath}" fetch --quiet --tags &> /dev/null || true
+	git -C "${GitPath}" symbolic-ref --short HEAD 2> /dev/null || git -C "${GitPath}" describe --tags --exact-match 2> /dev/null || git_best_branch "${GitPath}" "${DefaultBranch-}" "${LegacyBranch-}"
 }

</code_context>

<issue_to_address>
**issue (bug_risk):** Loss of explicit fatal behavior when the git path is invalid or inaccessible.

With `pushd "${GitPath}"`, an invalid or inaccessible repo path caused `fatal` and stopped execution. Using `git -C "${GitPath}"` now lets those failures fall through, potentially yielding empty or misleading results instead of a hard failure. If you still want invalid `GitPath` to be a hard error, add an explicit check that `GitPath` is a valid repo (or that `git -C` succeeds) and call `fatal`/return non‑zero when it isn’t.
</issue_to_address>

### Comment 2
<location> `.includes/cmdline.sh:668-669` </location>
<code_context>
 			local TemplatesBranch="${ParamsArray[1]-}"
-			run_script 'update_templates' "${TemplatesBranch-}"
-			run_script 'update_self' "${AppBranch-}" "${REST_OF_ARGS_ARRAY[@]}"
+			run_script 'update_templates' "${TemplatesBranch-}" || true
+			run_script 'update_self' "${AppBranch-}" "${REST_OF_ARGS_ARRAY[@]}" || true
 			result=$?
 			;;
</code_context>

<issue_to_address>
**issue (bug_risk):** Using `|| true` here forces `result` to always be 0 and hides update failures.

Because of the `|| true`, the last command in each pipeline becomes `true`, so `$?` (and thus `result`) is always 0, regardless of whether `update_templates` or `update_self` failed. Previously, `result` reflected `update_self`’s success/failure. If you want to avoid aborting but still return a meaningful status, capture each exit code before `|| true` and combine them, or at least don’t use `|| true` on the call whose exit code you need to inspect.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +9 to +10
git -C "${GitPath}" fetch --quiet --tags &> /dev/null || true
git -C "${GitPath}" symbolic-ref --short HEAD 2> /dev/null || git -C "${GitPath}" describe --tags --exact-match 2> /dev/null || git_best_branch "${GitPath}" "${DefaultBranch-}" "${LegacyBranch-}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Loss of explicit fatal behavior when the git path is invalid or inaccessible.

With pushd "${GitPath}", an invalid or inaccessible repo path caused fatal and stopped execution. Using git -C "${GitPath}" now lets those failures fall through, potentially yielding empty or misleading results instead of a hard failure. If you still want invalid GitPath to be a hard error, add an explicit check that GitPath is a valid repo (or that git -C succeeds) and call fatal/return non‑zero when it isn’t.

Comment on lines +668 to +669
run_script 'update_templates' "${TemplatesBranch-}" || true
run_script 'update_self' "${AppBranch-}" "${REST_OF_ARGS_ARRAY[@]}" || true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Using || true here forces result to always be 0 and hides update failures.

Because of the || true, the last command in each pipeline becomes true, so $? (and thus result) is always 0, regardless of whether update_templates or update_self failed. Previously, result reflected update_self’s success/failure. If you want to avoid aborting but still return a meaningful status, capture each exit code before || true and combine them, or at least don’t use || true on the call whose exit code you need to inspect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Automatic label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments