Skip to content
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

fix(build-cli): Fix up-to-date branch check #23968

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions build-tools/packages/build-cli/src/library/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,11 @@ export class Repository implements GitContext {
public async getShaForBranch(branch: string, remote?: string): Promise<string> {
const refspec =
remote === undefined ? `refs/heads/${branch}` : `refs/remotes/${remote}/${branch}`;
// result is a string of the form '64adcdba56deb16e0641c91ca825401a9f7a01f9 refs/heads/release/client/2.23'
Copy link
Contributor

Choose a reason for hiding this comment

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

I noticed this code has not changed in 2 years, and git show-ref also doesn't seem to have changed its output in the 2.x train of git... have we really been that lucky with this somehow still working?

If we only care about the sha, I'd suggest we use git show-ref --hash, and that we also validate that the result contains a single line to be completely sure the sha is actually for the thing we intend.

const result = await this.git.raw(`show-ref`, refspec);

return result;
const [sha] = result.split(" ");
return sha;
}

/**
Expand Down Expand Up @@ -465,7 +467,7 @@ export class Repository implements GitContext {
* Fetch branch
*/
public async fetchBranch(remote: string, branchName: string): Promise<void> {
await this.gitClient.fetch(remote, [branchName]);
await this.gitClient.fetch(remote, branchName);
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like we didn't catch this because there's a signature that can actually take a string array of options? Can we use the returned FetchResult to validate that what we want to happen actually happened? We know the branch name we want to fetch so I imagine that checking FetchResult.branches or FetchResult.updated could give us some confidence that this actually did what we want.

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export const CheckHasRemoteBranchUpToDate: CheckFunction = async (
return {
message: `Error when checking remote branch. Does the remote branch exist? Full error message:\n${
(error as Error).message
}`,
}\n${(error as Error).stack}`,
};
}

Expand Down