Skip to content

storage/filesystem: dotgit, unable to work with .git folder with temporal packfiles#6

Merged
mcuadros merged 3 commits into
masterfrom
pr-1153
Mar 9, 2020
Merged

storage/filesystem: dotgit, unable to work with .git folder with temporal packfiles#6
mcuadros merged 3 commits into
masterfrom
pr-1153

Conversation

@mcuadros

@mcuadros mcuadros commented Mar 9, 2020

Copy link
Copy Markdown
Member

Original created by @nulab at src-d/go-git#1153

fixes by #1149

First, I updated the test case to reproduce the problem, and I will add a patch to fix this problem.

vvatanabe added 3 commits May 17, 2019 13:58
Signed-off-by: Yuichi Watanabe <yuichi.watanabe.ja@gmail.com>
…1149

Signed-off-by: Yuichi Watanabe <yuichi.watanabe.ja@gmail.com>
…e prefix and suffix. Fixes #1149

Signed-off-by: Yuichi Watanabe <yuichi.watanabe.ja@gmail.com>
@mcuadros
mcuadros merged commit 586d45a into master Mar 9, 2020
@mcuadros
mcuadros deleted the pr-1153 branch March 10, 2020 00:47
rohankmr414 pushed a commit to rohankmr414/go-git that referenced this pull request Dec 18, 2022
…lones

Revert "git: Add support for deepening shallow clones (go-git#311)"
blitzy Bot pushed a commit to blitzy-research/go-git that referenced this pull request Jul 21, 2026
…handling

Address all 13 code-review findings for the mainline working-tree merge
capability (worktree_merge.go CREATE, worktree_commit.go UPDATE).

worktree_merge.go — complete plan-then-apply rewrite (findings #1-go-git#11):
- #1 Path safety: validate every planned path with existing validPath
  before any worktree/index mutation.
- #2 Mode/symlink/CRLF: materialise blobs via mode/symlink-aware
  checkoutFile after a symlink-safe RemoveAll; write computed content
  with the resolved Git mode (no more blanket 0644 text writes).
- go-git#3 Unrelated histories: diff against a canonical empty tree
  materialised in the object store, not a zero-value tree.
- go-git#4 File-vs-directory: complete base/ours/theirs state matrix; one-sided
  file<->directory transitions apply cleanly (matching git), only genuine
  two-sided divergence conflicts. treeNode now resolves a path blocked by
  a non-directory ancestor to "absent" (disambiguating the legitimate
  ErrObjectNotFound from genuine missing-object corruption, which is
  still surfaced) via a component-by-component walk.
- go-git#5 Add-add: an absent ancestor makes equal hashes the only clean case;
  every unequal addition (including empty-vs-non-empty) is forced into a
  stage-2/stage-3 conflict with both versions in markers.
- go-git#6 Conflict markers: exact tokens; each marker always begins on its own
  line even when a side lacks a terminal newline.
- go-git#7 Line merge: pure zero-width insertions at a gap are resolved before
  ranged regions so adjacent, non-overlapping edits no longer falsely
  conflict.
- go-git#8 Atomicity: plan and validate the whole merge before mutating; write
  .git/MERGE_HEAD before rewriting the index.
- go-git#9 Submodules: classified as their own leaf kind (never a directory);
  hashes/modes preserved through conflict/stage recording.
- go-git#10 Identity fallback: fill only the identity fields configuration did
  not supply, preserving a configured committer/author.
- go-git#11 Performance: filter the index in a single pass using conflict/
  subtree-prefix maps.

worktree_commit.go — MERGE_HEAD read (finding #1):
- Guard the MERGE_HEAD read with a portable Stat(.git)+IsDir() check so an
  ordinary commit in a linked worktree (whose .git is a pointer file) is
  never mistaken for a failed merge-state read (fixes the ENOTDIR
  regression reproduced by x/plumbing/worktree.TestWorktreeIsolation).
  Parents remain exactly [HEAD, MERGE_HEAD] built on a local options copy;
  MERGE_HEAD is removed only after the commit is durable and HEAD advances.

New sentinels ErrMergeConflicts and ErrUncommittedChanges are additive;
no public symbols removed/renamed. go.mod/go.sum unchanged.
blitzy Bot pushed a commit to blitzy-research/go-git that referenced this pull request Jul 21, 2026
Production fixes:
- #1 worktree_commit.go: distinguish genuine .git Stat errors (permission/IO) from not-exist and linked-worktree (.git is a file) so MERGE_HEAD access failures are surfaced instead of silently degrading to a single-parent commit; build merge parents [HEAD, MERGE_HEAD] on a local opts copy to avoid retry corruption.
- #2 worktree_merge.go: add mergeMode() to resolve filemode independently of content in the clean text-merge path, preserving an independent executable-bit change from the other side.
- go-git#3 worktree_merge.go: gitlink-aware planning/apply (wtMkdirSubmodule, wtRemoveAll, idxDirectStage0, idxDirectRemove) so submodule take/update/delete and file<->submodule / dir<->submodule transitions use direct index rows and explicit worktree ops instead of blob/Tree.File APIs; remove stale children before creating a submodule dir.
- go-git#4 worktree_merge.go: write .git/MERGE_HEAD as a preflight at the start of applyMergePlan (before any destructive worktree/index mutation) so a state-file write failure leaves the worktree and index untouched (no untracked half-merge).

Test fidelity (worktree_merge_test.go):
- go-git#5 replace lossy mergeTestStages with raw-entry assertions (exact row count/stage/hash/mode, no stage-0 on conflict, exactly one stage-0 on clean).
- go-git#6 add Add-resolution coverage: content-conflict resolve to ancestor/ours/theirs and sparse stage sets {1,2}/{1,3}/{2,3}, including the changed doAddFile Worktree=Unmodified branch, each asserting a single stage-0 row with the resolved blob hash and mode.
- go-git#7 fast-forward/up-to-date/dirty tests snapshot and compare every artifact (HEAD, object inventory, index, worktree, MERGE_HEAD-absence).
- go-git#8 content-conflict test asserts HEAD stays at ours plus exact stage hashes/modes, marker block and MERGE_HEAD text.
- go-git#9 rename TestThreeWayMerge -> TestWorktreeMergeThreeWayHelper so it is discovered by 'go test -run ^TestWorktreeMerge'.
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.

2 participants