GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — git: worktree, fix Add silently failing for absolute paths by tmchow · Pull Request #1949 · go-git/go-git

Conversation

@tmchow

@tmchow tmchow commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

Description

Worktree.Add() silently fails when given an absolute path. No error is returned, but the file is not added to the index because the index stores relative paths.

The fix converts absolute paths to worktree-relative paths using filepath.Rel() before updating the index. If the path is outside the worktree root, an error is returned.

Link to tracking issue

Fixes #1460

Testing

Added TestAddAbsolutePath which:

  1. Creates a repo with a real filesystem
  2. Writes a file
  3. Calls w.Add() with the absolute path
  4. Verifies the index contains the relative path
  5. Verifies status shows the file as staged

go test ./... and go vet ./... pass.

Documentation

N/A - behavior now matches git add /absolute/path.

This contribution was developed with AI assistance (Codex).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@tmchow
git: worktree, fix Add silently failing for absolute paths
7a4ee44
Convert absolute paths to worktree-relative paths in doAdd() before
updating the index. Return an error if the path is outside the worktree
root. Previously, absolute paths passed through filepath.Clean but were
never relativized, causing the file to not be tracked.

Fixes #1460
@tmchow tmchow mentioned this pull request Apr 1, 2026
Worktree.Add() silently fails for absolute paths #1460
Closed
pjbgf
pjbgf approved these changes Apr 2, 2026
View reviewed changes

@pjbgf pjbgf left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

@tmchow thanks for working on this. 🙇

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

tmchow reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@pjbgf
pjbgf merged commit 7aeb877 into go-git:main Apr 2, 2026
23 of 24 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@tmchow

tmchow commented Apr 2, 2026

Copy link
Copy Markdown
Contributor Author

@tmchow thanks for working on this. 🙇

You bet!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

Reviewers

@pjbgf pjbgf pjbgf approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Worktree.Add() silently fails for absolute paths

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@tmchow @pjbgf
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.