Skip to content

Commit

Permalink
fix(git-submodules): take git-tags and git-refs hostRules into ac…
Browse files Browse the repository at this point in the history
…count (#24250)
  • Loading branch information
Shegox committed Sep 28, 2023
1 parent f58cb01 commit 5f82d9d
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 2 deletions.
47 changes: 47 additions & 0 deletions lib/modules/manager/git-submodules/extract.spec.ts
Expand Up @@ -164,6 +164,53 @@ describe('modules/manager/git-submodules/extract', () => {
]);
});

it('combined username+pwd from host rule is used to detect branch for git-refs and git-tags', async () => {
gitMock.listRemote.mockResolvedValueOnce(
'ref: refs/heads/main HEAD\n5701164b9f5edba1f6ca114c491a564ffb55a964 HEAD'
);
hostRules.add({
hostType: 'git-refs',
matchHost: 'gitrefs.com',
username: 'git-refs-user',
password: 'git-refs-password',
});
hostRules.add({
hostType: 'git-tags',
matchHost: 'gittags.com',
username: 'git-tags-user',
password: 'git-tags-password',
});
const res = await extractPackageFile('', '.gitmodules.2', {});
expect(res?.deps).toHaveLength(1);
expect(res?.deps[0].currentValue).toBe('main');
expect(gitMock.env).toHaveBeenCalledWith({
GIT_CONFIG_COUNT: '6',
GIT_CONFIG_KEY_0:
'url.https://git-refs-user:git-refs-password@gitrefs.com/.insteadOf',
GIT_CONFIG_KEY_1:
'url.https://git-refs-user:git-refs-password@gitrefs.com/.insteadOf',
GIT_CONFIG_KEY_2:
'url.https://git-refs-user:git-refs-password@gitrefs.com/.insteadOf',
GIT_CONFIG_KEY_3:
'url.https://git-tags-user:git-tags-password@gittags.com/.insteadOf',
GIT_CONFIG_KEY_4:
'url.https://git-tags-user:git-tags-password@gittags.com/.insteadOf',
GIT_CONFIG_KEY_5:
'url.https://git-tags-user:git-tags-password@gittags.com/.insteadOf',
GIT_CONFIG_VALUE_0: 'ssh://git@gitrefs.com/',
GIT_CONFIG_VALUE_1: 'git@gitrefs.com:',
GIT_CONFIG_VALUE_2: 'https://gitrefs.com/',
GIT_CONFIG_VALUE_3: 'ssh://git@gittags.com/',
GIT_CONFIG_VALUE_4: 'git@gittags.com:',
GIT_CONFIG_VALUE_5: 'https://gittags.com/',
});
expect(gitMock.listRemote).toHaveBeenCalledWith([
'--symref',
'https://github.com/PowerShell/PowerShell-Docs',
'HEAD',
]);
});

it('extracts multiple submodules', async () => {
hostRules.add({ matchHost: 'github.com', token: '123test' });
hostRules.add({
Expand Down
5 changes: 4 additions & 1 deletion lib/modules/manager/git-submodules/extract.ts
Expand Up @@ -37,7 +37,10 @@ async function getUrl(
const headRefRe = regEx(/ref: refs\/heads\/(?<branch>\w+)\s/);

async function getDefaultBranch(subModuleUrl: string): Promise<string> {
const gitSubmoduleAuthEnvironmentVariables = getGitEnvironmentVariables();
const gitSubmoduleAuthEnvironmentVariables = getGitEnvironmentVariables([
'git-tags',
'git-refs',
]);
const gitEnv = {
// pass all existing env variables
...process.env,
Expand Down
1 change: 1 addition & 0 deletions lib/modules/manager/git-submodules/readme.md
Expand Up @@ -25,4 +25,5 @@ Next, all `hostRules` with both a token or username/password and `matchHost` wil
Rules from this list are converted to environment variable directives if they match _any_ of the following characteristics:

- No `hostType` is defined, or
- `hostType` is `git-tags` or `git-refs`, or
- `hostType` is a platform (`github`, `gitlab`, `azure`, etc.)
44 changes: 44 additions & 0 deletions lib/modules/manager/git-submodules/update.spec.ts
Expand Up @@ -87,5 +87,49 @@ describe('modules/manager/git-submodules/update', () => {
GIT_CONFIG_VALUE_2: 'https://github.com/',
});
});

it('returns content on update and uses git environment variables for git-tags/git-refs', async () => {
gitMock.submoduleUpdate.mockResolvedValue('');
gitMock.checkout.mockResolvedValue('');
hostRules.add({
hostType: 'git-refs',
matchHost: 'gitrefs.com',
username: 'git-refs-user',
password: 'git-refs-password',
});
hostRules.add({
hostType: 'git-tags',
matchHost: 'gittags.com',
username: 'git-tags-user',
password: 'git-tags-password',
});

const update = await updateDependency({
fileContent: '',
upgrade,
});
expect(update).toBe('');
expect(gitMock.env).toHaveBeenCalledWith({
GIT_CONFIG_COUNT: '6',
GIT_CONFIG_KEY_0:
'url.https://git-refs-user:git-refs-password@gitrefs.com/.insteadOf',
GIT_CONFIG_KEY_1:
'url.https://git-refs-user:git-refs-password@gitrefs.com/.insteadOf',
GIT_CONFIG_KEY_2:
'url.https://git-refs-user:git-refs-password@gitrefs.com/.insteadOf',
GIT_CONFIG_KEY_3:
'url.https://git-tags-user:git-tags-password@gittags.com/.insteadOf',
GIT_CONFIG_KEY_4:
'url.https://git-tags-user:git-tags-password@gittags.com/.insteadOf',
GIT_CONFIG_KEY_5:
'url.https://git-tags-user:git-tags-password@gittags.com/.insteadOf',
GIT_CONFIG_VALUE_0: 'ssh://git@gitrefs.com/',
GIT_CONFIG_VALUE_1: 'git@gitrefs.com:',
GIT_CONFIG_VALUE_2: 'https://gitrefs.com/',
GIT_CONFIG_VALUE_3: 'ssh://git@gittags.com/',
GIT_CONFIG_VALUE_4: 'git@gittags.com:',
GIT_CONFIG_VALUE_5: 'https://gittags.com/',
});
});
});
});
5 changes: 4 additions & 1 deletion lib/modules/manager/git-submodules/update.ts
Expand Up @@ -10,7 +10,10 @@ export default async function updateDependency({
upgrade,
}: UpdateDependencyConfig): Promise<string | null> {
const localDir = GlobalConfig.get('localDir');
const gitSubmoduleAuthEnvironmentVariables = getGitEnvironmentVariables();
const gitSubmoduleAuthEnvironmentVariables = getGitEnvironmentVariables([
'git-tags',
'git-refs',
]);
const gitEnv = {
// pass all existing env variables
...process.env,
Expand Down

0 comments on commit 5f82d9d

Please sign in to comment.