parameters:
  Repos: []
  DirectoryToSync: eng/common
  CommitMessage: commit-message-not-set

steps:

- ${{ each repo in parameters.Repos }}:
  - pwsh: |
      git clone --branch master https://github.com/azure/${{ repo }}
      $repoPath = "${{ repo }}/${{ parameters.DirectoryToSync }}"

      if (!(Test-Path $repoPath)) { mkdir $repoPath }
      Remove-Item -v -r $repoPath
      Copy-Item -v -r $(Build.SourcesDirectory)/${{ parameters.DirectoryToSync }} $repoPath
      Get-ChildItem -r $repoPath

    displayName: Copy ${{ parameters.DirectoryToSync }} from azure-sdk-tools to ${{ repo }}
    workingDirectory: $(System.DefaultWorkingDirectory)

  - template: eng/common/pipelines/templates/steps/create-pull-request.yml
    parameters:
      RepoName: ${{ repo }}
      PRBranchName: sync-${{ parameters.DirectoryToSync }}
      CommitMsg: ${{ parameters.CommitMessage }}
      PRTitle: ${{ parameters.CommitMessage }}
      PushArgs: -f
      WorkingDirectory: $(System.DefaultWorkingDirectory)/${{ repo }}
      ScriptDirectory: $(System.DefaultWorkingDirectory)/eng/common/scripts

parameters:
  Repos: []
  DirectoryToSync: eng/common
  CommitMessage: commit-message-not-set

steps:

- ${{ each repo in parameters.Repos }}:
  - pwsh: |
      git clone --branch master https://github.com/azure/${{ repo }}
      $repoPath = "${{ repo }}/${{ parameters.DirectoryToSync }}"

      if (!(Test-Path $repoPath)) { mkdir $repoPath }
      Remove-Item -v -r $repoPath
      Copy-Item -v -r $(Build.SourcesDirectory)/${{ parameters.DirectoryToSync }} $repoPath
      Get-ChildItem -r $repoPath

    displayName: Copy ${{ parameters.DirectoryToSync }} from azure-sdk-tools to ${{ repo }}
    workingDirectory: $(System.DefaultWorkingDirectory)

  - template: /eng/common/pipelines/templates/steps/create-pull-request.yml
    parameters:
      RepoName: ${{ repo }}
      PRBranchName: sync-${{ parameters.DirectoryToSync }}
      CommitMsg: ${{ parameters.CommitMessage }}
      PRTitle: ${{ parameters.CommitMessage }}
      PushArgs: -f
      WorkingDirectory: $(System.DefaultWorkingDirectory)/${{ repo }}
      ScriptDirectory: $(System.DefaultWorkingDirectory)/eng/common/scripts

Test adding "/" to template path to root it.
Test adding "/" to template path to root it.
