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 1 commit
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
8 changes: 5 additions & 3 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
const result = await this.git.raw(`show-ref`, refspec);

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

/**
Expand Down Expand Up @@ -459,13 +461,13 @@ export class Repository implements GitContext {
const currentSha = await this.getShaForBranch(branch);
const remoteSha = await this.getShaForBranch(branch, remote);
return remoteSha === currentSha;
}
}

/**
* 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
Loading