|
4 | 4 | "encoding/hex"
|
5 | 5 | "fmt"
|
6 | 6 | "os"
|
| 7 | + "path/filepath" |
7 | 8 | "strings"
|
8 | 9 | "sync"
|
9 | 10 |
|
@@ -313,7 +314,7 @@ func (r *Rewriter) Rewrite(opt *RewriteOptions) ([]byte, error) {
|
313 | 314 | return nil, errors.Wrap(err, tr.Tr.Get("could not find refs to update"))
|
314 | 315 | }
|
315 | 316 |
|
316 |
| - root, _ := r.db.Root() |
| 317 | + root, _ := r.gitDirectory() |
317 | 318 |
|
318 | 319 | updater := &refUpdater{
|
319 | 320 | cacheFn: r.uncacheCommit,
|
@@ -436,6 +437,15 @@ func copyEntryMode(e *gitobj.TreeEntry, mode int32) *gitobj.TreeEntry {
|
436 | 437 | return copied
|
437 | 438 | }
|
438 | 439 |
|
| 440 | +// gitDirectory returns a path to the .git directory on success. |
| 441 | +func (r *Rewriter) gitDirectory() (string, bool) { |
| 442 | + root, ok := r.db.Root() |
| 443 | + if ok { |
| 444 | + root = filepath.Join(root, "..") |
| 445 | + } |
| 446 | + return root, ok |
| 447 | +} |
| 448 | + |
439 | 449 | func (r *Rewriter) allows(typ gitobj.ObjectType, abs string) bool {
|
440 | 450 | switch typ {
|
441 | 451 | case gitobj.BlobObjectType:
|
@@ -529,7 +539,7 @@ func (r *Rewriter) refsToMigrate() ([]*git.Ref, error) {
|
529 | 539 | var refs []*git.Ref
|
530 | 540 | var err error
|
531 | 541 |
|
532 |
| - if root, ok := r.db.Root(); ok { |
| 542 | + if root, ok := r.gitDirectory(); ok { |
533 | 543 | refs, err = git.AllRefsIn(root)
|
534 | 544 | } else {
|
535 | 545 | refs, err = git.AllRefs()
|
@@ -568,7 +578,7 @@ func (r *Rewriter) scannerOpts() *git.ScanRefsOptions {
|
568 | 578 | Names: make(map[string]string),
|
569 | 579 | }
|
570 | 580 |
|
571 |
| - if root, ok := r.db.Root(); ok { |
| 581 | + if root, ok := r.gitDirectory(); ok { |
572 | 582 | opts.WorkingDir = root
|
573 | 583 | }
|
574 | 584 | return opts
|
|
0 commit comments