-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Fix hashing uncommitted changes #1448
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ce3b81a
b61dc9c
8b2dcf0
3ef4078
1dcbfe6
fd7299d
c0bc8d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,39 +25,40 @@ type PackageDepsOptions struct { | |
|
||
// GetPackageDeps Builds an object containing git hashes for the files under the specified `packagePath` folder. | ||
func GetPackageDeps(rootPath AbsolutePath, p *PackageDepsOptions) (map[turbopath.AnchoredUnixPath]string, error) { | ||
pkgPath := rootPath.Join(p.PackagePath) | ||
// Add all the checked in hashes. | ||
var result map[turbopath.AnchoredUnixPath]string | ||
if len(p.InputPatterns) == 0 { | ||
gitLsTreeOutput, err := gitLsTree(rootPath.Join(p.PackagePath)) | ||
gitLsTreeOutput, err := gitLsTree(pkgPath) | ||
if err != nil { | ||
return nil, fmt.Errorf("could not get git hashes for files in package %s: %w", p.PackagePath, err) | ||
} | ||
result = gitLsTreeOutput | ||
} else { | ||
gitLsFilesOutput, err := gitLsFiles(rootPath.Join(p.PackagePath), p.InputPatterns) | ||
gitLsFilesOutput, err := gitLsFiles(pkgPath, p.InputPatterns) | ||
if err != nil { | ||
return nil, fmt.Errorf("could not get git hashes for file patterns %v in package %s: %w", p.InputPatterns, p.PackagePath, err) | ||
} | ||
result = gitLsFilesOutput | ||
} | ||
|
||
// Update the checked in hashes with the current repo status | ||
gitStatusOutput, err := gitStatus(rootPath.Join(p.PackagePath), p.InputPatterns) | ||
// The paths returned from this call are anchored at the package directory | ||
gitStatusOutput, err := gitStatus(pkgPath, p.InputPatterns) | ||
if err != nil { | ||
return nil, fmt.Errorf("Could not get git hashes from git status: %v", err) | ||
} | ||
|
||
var filesToHash []turbopath.AnchoredUnixPath | ||
var filesToHash []turbopath.AnchoredSystemPath | ||
for filePath, status := range gitStatusOutput { | ||
if status.isDelete() { | ||
delete(result, filePath) | ||
} else { | ||
filesToHash = append(filesToHash, filePath) | ||
filesToHash = append(filesToHash, filePath.ToSystemPath()) | ||
} | ||
} | ||
|
||
convertedRootPath := turbopath.AbsoluteSystemPathFromUpstream(rootPath.ToString()) | ||
hashes, err := gitHashObject(convertedRootPath, turbopath.AnchoredUnixPathArray(filesToHash).ToSystemPathArray()) | ||
hashes, err := gitHashObject(turbopath.AbsoluteSystemPathFromUpstream(pkgPath.ToString()), filesToHash) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need a way to specify the "expected" anchors. I don't think I can do that in the Go type system without doing type RepoAnchoredSystemPath interface {
AnchoredSystemPath
}
type PackageAnchoredSystemPath interface {
AnchoredSystemPath
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Worth drawing attention to this line: |
||
if err != nil { | ||
return nil, err | ||
} | ||
|
@@ -89,10 +90,10 @@ func GetHashableDeps(rootPath AbsolutePath, files []turbopath.AbsoluteSystemPath | |
// gitHashObject returns a map of paths to their SHA hashes calculated by passing the paths `git hash-object`. | ||
// `git hash-object` expects paths to use Unix separators, even on Windows. | ||
// | ||
// Note: paths of files to hash passed to `git hash-object` are processed as relative to the *repository* root. | ||
// For that reason we convert all input paths and make them relative to the rootPath prior to passing them | ||
// Note: paths of files to hash passed to `git hash-object` are processed as relative to the given anchor. | ||
// For that reason we convert all input paths and make them relative to the anchor prior to passing them | ||
// to `git hash-object`. | ||
func gitHashObject(rootPath turbopath.AbsoluteSystemPath, filesToHash []turbopath.AnchoredSystemPath) (map[turbopath.AnchoredUnixPath]string, error) { | ||
func gitHashObject(anchor turbopath.AbsoluteSystemPath, filesToHash []turbopath.AnchoredSystemPath) (map[turbopath.AnchoredUnixPath]string, error) { | ||
fileCount := len(filesToHash) | ||
output := make(map[turbopath.AnchoredUnixPath]string, fileCount) | ||
|
||
|
@@ -102,7 +103,7 @@ func gitHashObject(rootPath turbopath.AbsoluteSystemPath, filesToHash []turbopat | |
"hash-object", // hash a file, | ||
"--stdin-paths", // using a list of newline-separated paths from stdin. | ||
) | ||
cmd.Dir = rootPath.ToString() // Start at this directory. | ||
cmd.Dir = anchor.ToString() // Start at this directory. | ||
|
||
// The functionality for gitHashObject is different enough that it isn't reasonable to | ||
// generalize the behavior for `runGitCmd`. In fact, it doesn't even use the `gitoutput` | ||
|
@@ -125,7 +126,7 @@ func gitHashObject(rootPath turbopath.AbsoluteSystemPath, filesToHash []turbopat | |
// This function's result needs to be relative to `rootPath`. | ||
// We convert all files to absolute paths and assume that they will be inside of the repository. | ||
for _, file := range filesToHash { | ||
converted := file.RestoreAnchor(rootPath) | ||
converted := file.RestoreAnchor(anchor) | ||
|
||
// `git hash-object` expects paths to use Unix separators, even on Windows. | ||
// `git hash-object` expects paths to be one per line so we must escape newlines. | ||
|
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.
Thanks for cleaning this up!