|
| 1 | +name: git submodule init |
| 2 | + |
| 3 | +inputs: |
| 4 | + working-directory: |
| 5 | + description: root directory of parent repository |
| 6 | + required: false |
| 7 | + submodule: |
| 8 | + description: path of submodule relative to parent repository root |
| 9 | + required: true |
| 10 | + |
| 11 | +runs: |
| 12 | + using: composite |
| 13 | + steps: |
| 14 | + - run: git submodule init "$SUBMODULE" |
| 15 | + env: |
| 16 | + SUBMODULE: ${{inputs.submodule}} |
| 17 | + working-directory: ${{inputs.working-directory}} |
| 18 | + shell: bash |
| 19 | + - id: path |
| 20 | + run: (echo -n gitdir=; git rev-parse --absolute-git-dir) | tee -a $GITHUB_OUTPUT |
| 21 | + working-directory: ${{inputs.working-directory}} |
| 22 | + shell: bash |
| 23 | + - run: mkdir -p "$DIR" |
| 24 | + env: |
| 25 | + DIR: ${{steps.path.outputs.gitdir}}/modules/${{inputs.submodule}} |
| 26 | + working-directory: ${{inputs.working-directory}} |
| 27 | + shell: bash |
| 28 | + - run: git -c advice.defaultBranchName=false init --separate-git-dir="$DIR" "$SUBMODULE" |
| 29 | + env: |
| 30 | + DIR: ${{steps.path.outputs.gitdir}}/modules/${{inputs.submodule}} |
| 31 | + SUBMODULE: ${{inputs.submodule}} |
| 32 | + working-directory: ${{inputs.working-directory}} |
| 33 | + shell: bash |
| 34 | + - id: config |
| 35 | + run: (echo -n url=; git config submodule."$SUBMODULE".url) | tee -a $GITHUB_OUTPUT |
| 36 | + env: |
| 37 | + SUBMODULE: ${{inputs.submodule}} |
| 38 | + working-directory: ${{inputs.working-directory}} |
| 39 | + shell: bash |
| 40 | + - run: git -C "$SUBMODULE" remote add origin "$URL" |
| 41 | + env: |
| 42 | + SUBMODULE: ${{inputs.submodule}} |
| 43 | + URL: ${{steps.config.outputs.url}} |
| 44 | + working-directory: ${{inputs.working-directory}} |
| 45 | + shell: bash |
| 46 | + - id: commit |
| 47 | + run: (echo -n commit=; git rev-parse :"$SUBMODULE") | tee -a $GITHUB_OUTPUT |
| 48 | + env: |
| 49 | + SUBMODULE: ${{inputs.submodule}} |
| 50 | + working-directory: ${{inputs.working-directory}} |
| 51 | + shell: bash |
| 52 | + - run: git -C "$SUBMODULE" fetch origin --refmap= --depth=1 "$COMMIT" |
| 53 | + env: |
| 54 | + COMMIT: ${{steps.commit.outputs.commit}} |
| 55 | + SUBMODULE: ${{inputs.submodule}} |
| 56 | + working-directory: ${{inputs.working-directory}} |
| 57 | + shell: bash |
| 58 | + - run: git -C "$SUBMODULE" -c advice.detachedHead=false checkout FETCH_HEAD |
| 59 | + env: |
| 60 | + SUBMODULE: ${{inputs.submodule}} |
| 61 | + working-directory: ${{inputs.working-directory}} |
| 62 | + shell: bash |
0 commit comments