Skip to content

Commit

Permalink
fix(turborepo): SCM tests and renaming (#4462)
Browse files Browse the repository at this point in the history
### Description

Added more testing to SCM and renamed variables to be more
understandable (repo_root -> git_root, monorepo_root -> turbo_root)

### Testing Instructions

Added tests on Rust side for deleting files and adding file to index.
  • Loading branch information
NicholasLYang authored Apr 11, 2023
1 parent 9a0fa8b commit 1cbba83
Show file tree
Hide file tree
Showing 7 changed files with 449 additions and 172 deletions.
14 changes: 7 additions & 7 deletions cli/internal/ffi/ffi.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,15 @@ func stringToRef(s string) *string {
}

// ChangedFiles returns the files changed in between two commits, the workdir and the index, and optionally untracked files
func ChangedFiles(repoRoot string, monorepoRoot string, fromCommit string, toCommit string) ([]string, error) {
func ChangedFiles(gitRoot string, turboRoot string, fromCommit string, toCommit string) ([]string, error) {
fromCommitRef := stringToRef(fromCommit)
toCommitRef := stringToRef(toCommit)

req := ffi_proto.ChangedFilesReq{
RepoRoot: repoRoot,
FromCommit: fromCommitRef,
ToCommit: toCommitRef,
MonorepoRoot: monorepoRoot,
GitRoot: gitRoot,
FromCommit: fromCommitRef,
ToCommit: toCommitRef,
TurboRoot: turboRoot,
}

reqBuf := Marshal(&req)
Expand All @@ -144,9 +144,9 @@ func ChangedFiles(repoRoot string, monorepoRoot string, fromCommit string, toCom
}

// PreviousContent returns the content of a file at a previous commit
func PreviousContent(repoRoot, fromCommit, filePath string) ([]byte, error) {
func PreviousContent(gitRoot, fromCommit, filePath string) ([]byte, error) {
req := ffi_proto.PreviousContentReq{
RepoRoot: repoRoot,
GitRoot: gitRoot,
FromCommit: fromCommit,
FilePath: filePath,
}
Expand Down
176 changes: 88 additions & 88 deletions cli/internal/ffi/proto/messages.pb.go

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions cli/internal/scm/git_go.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build go || !rust
// +build go !rust

// Package scm abstracts operations on various tools like git
// Currently, only git is supported.
//
Expand Down
28 changes: 28 additions & 0 deletions cli/internal/scm/git_rust.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Package scm abstracts operations on various tools like git
// Currently, only git is supported.
//
// Adapted from https://github.com/thought-machine/please/tree/master/src/scm
// Copyright Thought Machine, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
//go:build rust
// +build rust

package scm

import (
"github.com/vercel/turbo/cli/internal/ffi"
)

// git implements operations on a git repository.
type git struct {
repoRoot string
}

// ChangedFiles returns a list of modified files since the given commit, optionally including untracked files.
func (g *git) ChangedFiles(fromCommit string, toCommit string, monorepoRoot string) ([]string, error) {
return ffi.ChangedFiles(g.repoRoot, monorepoRoot, fromCommit, toCommit)
}

func (g *git) PreviousContent(fromCommit string, filePath string) ([]byte, error) {
return ffi.PreviousContent(g.repoRoot, fromCommit, filePath)
}
8 changes: 4 additions & 4 deletions crates/turborepo-ffi/messages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ message GlobRespList {
}

message ChangedFilesReq {
string repo_root = 1;
string monorepo_root = 2;
string git_root = 1;
string turbo_root = 2;
optional string from_commit = 3;
optional string to_commit = 4;
string to_commit = 4;
}

message ChangedFilesResp {
Expand All @@ -42,7 +42,7 @@ message ChangedFilesList {
}

message PreviousContentReq {
string repo_root = 1;
string git_root = 1;
string from_commit = 2;
string file_path = 3;
}
Expand Down
10 changes: 5 additions & 5 deletions crates/turborepo-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ pub extern "C" fn changed_files(buffer: Buffer) -> Buffer {
}
};

let commit_range = req.from_commit.as_deref().zip(req.to_commit.as_deref());
let response = match turborepo_scm::git::changed_files(
req.repo_root.into(),
req.monorepo_root.into(),
commit_range,
req.git_root.into(),
req.turbo_root.into(),
req.from_commit.as_deref(),
&req.to_commit,
) {
Ok(files) => {
let files: Vec<_> = files.into_iter().collect();
Expand Down Expand Up @@ -108,7 +108,7 @@ pub extern "C" fn previous_content(buffer: Buffer) -> Buffer {
};

let response = match turborepo_scm::git::previous_content(
req.repo_root.into(),
req.git_root.into(),
&req.from_commit,
PathBuf::from(req.file_path),
) {
Expand Down
Loading

0 comments on commit 1cbba83

Please sign in to comment.