@@ -4934,31 +4934,6 @@ describe('DataSource', () => {
49344934 } ) ;
49354935 } ) ;
49364936
4937- describe ( 'pushTag' , ( ) => {
4938- it ( 'Should push a tag to the remote' , async ( ) => {
4939- // Setup
4940- mockGitSuccessOnce ( ) ;
4941-
4942- // Run
4943- const result = await dataSource . pushTag ( '/path/to/repo' , 'tag-name' , 'origin' ) ;
4944-
4945- // Assert
4946- expect ( result ) . toBe ( null ) ;
4947- expect ( spyOnSpawn ) . toBeCalledWith ( '/path/to/git' , [ 'push' , 'origin' , 'tag-name' ] , expect . objectContaining ( { cwd : '/path/to/repo' } ) ) ;
4948- } ) ;
4949-
4950- it ( 'Should return an error message thrown by git' , async ( ) => {
4951- // Setup
4952- mockGitThrowingErrorOnce ( ) ;
4953-
4954- // Run
4955- const result = await dataSource . pushTag ( '/path/to/repo' , 'tag-name' , 'origin' ) ;
4956-
4957- // Assert
4958- expect ( result ) . toBe ( 'error message' ) ;
4959- } ) ;
4960- } ) ;
4961-
49624937 describe ( 'pushBranchToMultipleRemotes' , ( ) => {
49634938 it ( 'Should push a branch to one remote' , async ( ) => {
49644939 // Setup
@@ -5009,13 +4984,13 @@ describe('DataSource', () => {
50094984 } ) ;
50104985 } ) ;
50114986
5012- describe ( 'pushTagToMultipleRemotes ' , ( ) => {
4987+ describe ( 'pushTag ' , ( ) => {
50134988 it ( 'Should push a tag to one remote' , async ( ) => {
50144989 // Setup
50154990 mockGitSuccessOnce ( ) ;
50164991
50174992 // Run
5018- const result = await dataSource . pushTagToMultipleRemotes ( '/path/to/repo' , 'tag-name' , [ 'origin' ] ) ;
4993+ const result = await dataSource . pushTag ( '/path/to/repo' , 'tag-name' , [ 'origin' ] , '1a2b3c4d5e6f1a2b3c4d5e6f1a2b3c4d5e6f1a2b' , true ) ;
50194994
50204995 // Assert
50214996 expect ( result ) . toStrictEqual ( [ null ] ) ;
@@ -5028,21 +5003,140 @@ describe('DataSource', () => {
50285003 mockGitSuccessOnce ( ) ;
50295004
50305005 // Run
5031- const result = await dataSource . pushTagToMultipleRemotes ( '/path/to/repo' , 'tag-name' , [ 'origin' , 'other-origin' ] ) ;
5006+ const result = await dataSource . pushTag ( '/path/to/repo' , 'tag-name' , [ 'origin' , 'other-origin' ] , '1a2b3c4d5e6f1a2b3c4d5e6f1a2b3c4d5e6f1a2b' , true ) ;
50325007
50335008 // Assert
50345009 expect ( result ) . toStrictEqual ( [ null , null ] ) ;
50355010 expect ( spyOnSpawn ) . toBeCalledWith ( '/path/to/git' , [ 'push' , 'origin' , 'tag-name' ] , expect . objectContaining ( { cwd : '/path/to/repo' } ) ) ;
50365011 expect ( spyOnSpawn ) . toBeCalledWith ( '/path/to/git' , [ 'push' , 'other-origin' , 'tag-name' ] , expect . objectContaining ( { cwd : '/path/to/repo' } ) ) ;
50375012 } ) ;
50385013
5014+ describe ( 'Should check that the commit exists on each remote the tag is being pushed to' , ( ) => {
5015+ it ( 'Commit exists on all remotes' , async ( ) => {
5016+ // Setup
5017+ mockGitSuccessOnce (
5018+ ' origin/master\n' +
5019+ ' other-origin/master\n'
5020+ ) ;
5021+ mockGitSuccessOnce ( ) ;
5022+ mockGitSuccessOnce ( ) ;
5023+
5024+ // Run
5025+ const result = await dataSource . pushTag ( '/path/to/repo' , 'tag-name' , [ 'origin' , 'other-origin' ] , '1a2b3c4d5e6f1a2b3c4d5e6f1a2b3c4d5e6f1a2b' , false ) ;
5026+
5027+ // Assert
5028+ expect ( result ) . toStrictEqual ( [ null , null ] ) ;
5029+ expect ( spyOnSpawn ) . toBeCalledWith ( '/path/to/git' , [ 'branch' , '-r' , '--no-color' , '--contains=1a2b3c4d5e6f1a2b3c4d5e6f1a2b3c4d5e6f1a2b' ] , expect . objectContaining ( { cwd : '/path/to/repo' } ) ) ;
5030+ expect ( spyOnSpawn ) . toBeCalledWith ( '/path/to/git' , [ 'push' , 'origin' , 'tag-name' ] , expect . objectContaining ( { cwd : '/path/to/repo' } ) ) ;
5031+ expect ( spyOnSpawn ) . toBeCalledWith ( '/path/to/git' , [ 'push' , 'other-origin' , 'tag-name' ] , expect . objectContaining ( { cwd : '/path/to/repo' } ) ) ;
5032+ } ) ;
5033+
5034+ it ( 'Commit exists on one remote' , async ( ) => {
5035+ // Setup
5036+ mockGitSuccessOnce (
5037+ ' origin/master\n'
5038+ ) ;
5039+
5040+ // Run
5041+ const result = await dataSource . pushTag ( '/path/to/repo' , 'tag-name' , [ 'origin' , 'other-origin' ] , '1a2b3c4d5e6f1a2b3c4d5e6f1a2b3c4d5e6f1a2b' , false ) ;
5042+
5043+ // Assert
5044+ expect ( result ) . toStrictEqual ( [ 'VSCODE_GIT_GRAPH:PUSH_TAG:COMMIT_NOT_ON_REMOTE:[\"other-origin\"]' ] ) ;
5045+ expect ( spyOnSpawn ) . toHaveBeenCalledTimes ( 1 ) ;
5046+ expect ( spyOnSpawn ) . toBeCalledWith ( '/path/to/git' , [ 'branch' , '-r' , '--no-color' , '--contains=1a2b3c4d5e6f1a2b3c4d5e6f1a2b3c4d5e6f1a2b' ] , expect . objectContaining ( { cwd : '/path/to/repo' } ) ) ;
5047+ } ) ;
5048+
5049+ it ( 'Commit doesn\'t exist on any remote' , async ( ) => {
5050+ // Setup
5051+ mockGitSuccessOnce ( '' ) ;
5052+
5053+ // Run
5054+ const result = await dataSource . pushTag ( '/path/to/repo' , 'tag-name' , [ 'origin' , 'other-origin' ] , '1a2b3c4d5e6f1a2b3c4d5e6f1a2b3c4d5e6f1a2b' , false ) ;
5055+
5056+ // Assert
5057+ expect ( result ) . toStrictEqual ( [ 'VSCODE_GIT_GRAPH:PUSH_TAG:COMMIT_NOT_ON_REMOTE:[\"origin\",\"other-origin\"]' ] ) ;
5058+ expect ( spyOnSpawn ) . toHaveBeenCalledTimes ( 1 ) ;
5059+ expect ( spyOnSpawn ) . toBeCalledWith ( '/path/to/git' , [ 'branch' , '-r' , '--no-color' , '--contains=1a2b3c4d5e6f1a2b3c4d5e6f1a2b3c4d5e6f1a2b' ] , expect . objectContaining ( { cwd : '/path/to/repo' } ) ) ;
5060+ } ) ;
5061+
5062+ it ( 'Handles remote branches with symbolic references' , async ( ) => {
5063+ // Setup
5064+ mockGitSuccessOnce (
5065+ ' origin/HEAD -> origin/master\n' +
5066+ ' other-origin/master\n'
5067+ ) ;
5068+ mockGitSuccessOnce ( ) ;
5069+ mockGitSuccessOnce ( ) ;
5070+
5071+ // Run
5072+ const result = await dataSource . pushTag ( '/path/to/repo' , 'tag-name' , [ 'origin' , 'other-origin' ] , '1a2b3c4d5e6f1a2b3c4d5e6f1a2b3c4d5e6f1a2b' , false ) ;
5073+
5074+ // Assert
5075+ expect ( result ) . toStrictEqual ( [ null , null ] ) ;
5076+ expect ( spyOnSpawn ) . toBeCalledWith ( '/path/to/git' , [ 'branch' , '-r' , '--no-color' , '--contains=1a2b3c4d5e6f1a2b3c4d5e6f1a2b3c4d5e6f1a2b' ] , expect . objectContaining ( { cwd : '/path/to/repo' } ) ) ;
5077+ expect ( spyOnSpawn ) . toBeCalledWith ( '/path/to/git' , [ 'push' , 'origin' , 'tag-name' ] , expect . objectContaining ( { cwd : '/path/to/repo' } ) ) ;
5078+ expect ( spyOnSpawn ) . toBeCalledWith ( '/path/to/git' , [ 'push' , 'other-origin' , 'tag-name' ] , expect . objectContaining ( { cwd : '/path/to/repo' } ) ) ;
5079+ } ) ;
5080+
5081+ it ( 'Handles remote names that contain slashes' , async ( ) => {
5082+ // Setup
5083+ mockGitSuccessOnce (
5084+ ' origin/master\n' +
5085+ ' other/origin/master\n'
5086+ ) ;
5087+ mockGitSuccessOnce ( ) ;
5088+ mockGitSuccessOnce ( ) ;
5089+
5090+ // Run
5091+ const result = await dataSource . pushTag ( '/path/to/repo' , 'tag-name' , [ 'origin' , 'other/origin' ] , '1a2b3c4d5e6f1a2b3c4d5e6f1a2b3c4d5e6f1a2b' , false ) ;
5092+
5093+ // Assert
5094+ expect ( result ) . toStrictEqual ( [ null , null ] ) ;
5095+ expect ( spyOnSpawn ) . toBeCalledWith ( '/path/to/git' , [ 'branch' , '-r' , '--no-color' , '--contains=1a2b3c4d5e6f1a2b3c4d5e6f1a2b3c4d5e6f1a2b' ] , expect . objectContaining ( { cwd : '/path/to/repo' } ) ) ;
5096+ expect ( spyOnSpawn ) . toBeCalledWith ( '/path/to/git' , [ 'push' , 'origin' , 'tag-name' ] , expect . objectContaining ( { cwd : '/path/to/repo' } ) ) ;
5097+ expect ( spyOnSpawn ) . toBeCalledWith ( '/path/to/git' , [ 'push' , 'other/origin' , 'tag-name' ] , expect . objectContaining ( { cwd : '/path/to/repo' } ) ) ;
5098+ } ) ;
5099+
5100+ it ( 'Ignores records that aren\'t branches in the git branch output' , async ( ) => {
5101+ // Setup
5102+ mockGitSuccessOnce (
5103+ ' (invalid branch)\n' +
5104+ ' other-origin/master\n'
5105+ ) ;
5106+
5107+ // Run
5108+ const result = await dataSource . pushTag ( '/path/to/repo' , 'tag-name' , [ 'origin' , 'other-origin' ] , '1a2b3c4d5e6f1a2b3c4d5e6f1a2b3c4d5e6f1a2b' , false ) ;
5109+
5110+ // Assert
5111+ expect ( result ) . toStrictEqual ( [ 'VSCODE_GIT_GRAPH:PUSH_TAG:COMMIT_NOT_ON_REMOTE:[\"origin\"]' ] ) ;
5112+ expect ( spyOnSpawn ) . toHaveBeenCalledTimes ( 1 ) ;
5113+ expect ( spyOnSpawn ) . toBeCalledWith ( '/path/to/git' , [ 'branch' , '-r' , '--no-color' , '--contains=1a2b3c4d5e6f1a2b3c4d5e6f1a2b3c4d5e6f1a2b' ] , expect . objectContaining ( { cwd : '/path/to/repo' } ) ) ;
5114+ } ) ;
5115+
5116+ it ( 'Ignores when Git throws an exception' , async ( ) => {
5117+ // Setup
5118+ mockGitThrowingErrorOnce ( ) ;
5119+ mockGitSuccessOnce ( ) ;
5120+ mockGitSuccessOnce ( ) ;
5121+
5122+ // Run
5123+ const result = await dataSource . pushTag ( '/path/to/repo' , 'tag-name' , [ 'origin' , 'other-origin' ] , '1a2b3c4d5e6f1a2b3c4d5e6f1a2b3c4d5e6f1a2b' , false ) ;
5124+
5125+ // Assert
5126+ expect ( result ) . toStrictEqual ( [ null , null ] ) ;
5127+ expect ( spyOnSpawn ) . toBeCalledWith ( '/path/to/git' , [ 'branch' , '-r' , '--no-color' , '--contains=1a2b3c4d5e6f1a2b3c4d5e6f1a2b3c4d5e6f1a2b' ] , expect . objectContaining ( { cwd : '/path/to/repo' } ) ) ;
5128+ expect ( spyOnSpawn ) . toBeCalledWith ( '/path/to/git' , [ 'push' , 'origin' , 'tag-name' ] , expect . objectContaining ( { cwd : '/path/to/repo' } ) ) ;
5129+ expect ( spyOnSpawn ) . toBeCalledWith ( '/path/to/git' , [ 'push' , 'other-origin' , 'tag-name' ] , expect . objectContaining ( { cwd : '/path/to/repo' } ) ) ;
5130+ } ) ;
5131+ } ) ;
5132+
50395133 it ( 'Should push a tag to multiple remotes, stopping if an error occurs' , async ( ) => {
50405134 // Setup
50415135 mockGitSuccessOnce ( ) ;
50425136 mockGitThrowingErrorOnce ( ) ;
50435137
50445138 // Run
5045- const result = await dataSource . pushTagToMultipleRemotes ( '/path/to/repo' , 'tag-name' , [ 'origin' , 'other-origin' , 'another-origin' ] ) ;
5139+ const result = await dataSource . pushTag ( '/path/to/repo' , 'tag-name' , [ 'origin' , 'other-origin' , 'another-origin' ] , '1a2b3c4d5e6f1a2b3c4d5e6f1a2b3c4d5e6f1a2b' , true ) ;
50465140
50475141 // Assert
50485142 expect ( result ) . toStrictEqual ( [ null , 'error message' ] ) ;
@@ -5052,7 +5146,7 @@ describe('DataSource', () => {
50525146
50535147 it ( 'Should return an error when no remotes are specified' , async ( ) => {
50545148 // Run
5055- const result = await dataSource . pushTagToMultipleRemotes ( '/path/to/repo' , 'tag-name' , [ ] ) ;
5149+ const result = await dataSource . pushTag ( '/path/to/repo' , 'tag-name' , [ ] , '1a2b3c4d5e6f1a2b3c4d5e6f1a2b3c4d5e6f1a2b' , true ) ;
50565150
50575151 // Assert
50585152 expect ( result ) . toStrictEqual ( [ 'No remote(s) were specified to push the tag tag-name to.' ] ) ;
0 commit comments