Skip to content

app: make build/.gitkeep postbuild step git-worktree friendly#1311

Merged
jamaljsr merged 2 commits into
lightninglabs:masterfrom
0xfandom:fix/1022-dockerfile-worktree-gitkeep
May 22, 2026
Merged

app: make build/.gitkeep postbuild step git-worktree friendly#1311
jamaljsr merged 2 commits into
lightninglabs:masterfrom
0xfandom:fix/1022-dockerfile-worktree-gitkeep

Conversation

@0xfandom

Copy link
Copy Markdown
Contributor

Fixes #1022.

Problem

When the working copy of lightning-terminal is a git worktree, the top-level .git is a file like gitdir: ../.bare/worktrees/<name> rather than a real .git/ directory. Building with dev.Dockerfile then fails:

fatal: not a git repository: /go/src/github.com/lightninglabs/lightning-terminal/../.bare/worktrees/<name>
error Command failed with exit code 128.

This happens because dev.Dockerfile copies the working tree into the container with COPY ., but the path that the .git file points at lives outside the build context, so any git invocation inside the container errors out. The first git call inside the build comes from the postbuild script in app/package.json:

"postbuild": "git restore build/.gitkeep",

That script aborts, yarn build fails, and the image build dies.

Fix

Make the postbuild step tolerant of environments where git is not usable. git restore is still preferred — it preserves the exact byte contents from the index, including any line-ending normalisation the original app: use git restore to re-create .gitkeep file commit was guarding against — and the fallback only kicks in when git cannot reach the worktree (which is exactly the case inside the dev image build):

"postbuild": "git restore build/.gitkeep 2>/dev/null || printf '# Keep directory in git.\n' > build/.gitkeep"

Verification

  • On a normal checkout, yarn --cwd app build still restores build/.gitkeep from the index via git restore (the first branch of the ||).
  • In a directory where git cannot find a repository (e.g. a copy outside any git worktree, which mirrors the dev.Dockerfile situation), the second branch runs and writes the same content the file has at HEAD, so git diff is still clean once the file is back on the host.

The `postbuild` script for the web UI invokes `git restore
build/.gitkeep` to bring back the placeholder file after
react-scripts wipes the build directory. When the repository is
checked out as a `git worktree`, the top-level `.git` is a file that
points at a worktree directory on the host. The dev.Dockerfile build
copies the working tree into the container with `COPY .`, but the
path referenced by that `.git` pointer is not part of the build
context, so any git invocation inside the container aborts with
`fatal: not a git repository`, causing `yarn build` and the whole
image build to fail.

Fall back to writing the `.gitkeep` content directly when
`git restore` is not usable. `git restore` is still preferred so that
the byte-for-byte contents from the index are used when git is
available; the fallback only kicks in when git cannot reach the
worktree, which is exactly the case inside the dev image build.
@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a build failure occurring when the project is built inside a Docker container while the host environment uses git worktrees. By making the postbuild script tolerant of git failures, the build process can now successfully complete even when the git repository structure is not fully accessible within the build context.

Highlights

  • Build Process Robustness: Updated the postbuild script in app/package.json to be resilient against environments where git is unavailable or inaccessible, such as within Docker builds using git worktrees.
  • Fallback Mechanism: Implemented a fallback mechanism that attempts to use 'git restore' first, and if that fails, creates the .gitkeep file using 'printf' to ensure the build succeeds.
New Features

🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request updates the postbuild script in app/package.json to ensure the build/.gitkeep file is restored or recreated after a build. A review comment correctly identifies that the use of POSIX-specific shell syntax (2>/dev/null and printf) will cause failures on Windows environments and suggests a cross-platform Node.js one-liner as a replacement.

Comment thread app/package.json
"develop": "REACT_APP_USE_SAMPLE_DATA=true yarn start",
"build": "react-scripts build",
"postbuild": "git restore build/.gitkeep",
"postbuild": "git restore build/.gitkeep 2>/dev/null || printf '# Keep directory in git.\\n' > build/.gitkeep",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The updated postbuild script uses POSIX-specific syntax (2>/dev/null and printf) which is not compatible with Windows cmd.exe. This will cause the build to fail for developers on Windows. To maintain cross-platform compatibility, consider using a Node.js one-liner to handle the git restoration and fallback logic.

Suggested change
"postbuild": "git restore build/.gitkeep 2>/dev/null || printf '# Keep directory in git.\\n' > build/.gitkeep",
"postbuild": "node -e \"try { require('child_process').execSync('git restore build/.gitkeep', { stdio: 'ignore' }); } catch (e) { require('fs').writeFileSync('build/.gitkeep', '# Keep directory in git.\\n'); }\"",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think this is needed as this is for Docker builds (i.e. linux).

@ViktorT-11 ViktorT-11 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, I think this change looks good!

It'd be valuable if @jamaljsr could take a quick look at this PR as well as it's docker related.

Additionally @ZZiigguurraatt, can you test this to see that it resolves your issue?

Comment thread app/package.json
"develop": "REACT_APP_USE_SAMPLE_DATA=true yarn start",
"build": "react-scripts build",
"postbuild": "git restore build/.gitkeep",
"postbuild": "git restore build/.gitkeep 2>/dev/null || printf '# Keep directory in git.\\n' > build/.gitkeep",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think this is needed as this is for Docker builds (i.e. linux).

@ViktorT-11
ViktorT-11 requested a review from jamaljsr May 20, 2026 11:34

@jamaljsr jamaljsr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

tACK LGTM 👌

Confirmed the broken docker build on a worktree which is resolved with this fix. Thanks for the contribution.

@jamaljsr
jamaljsr merged commit 41012e4 into lightninglabs:master May 22, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

can't build from dev.Dockerfile when using git worktree

3 participants