2021年7月29日 星期四

Implicitly loading submodules in Jenkins pipeline stages

I assume you have been using the git step so far to clone a repository.

However for advanced features (like submodules) there's the checkout step available: https://jenkins.io/doc/pipeline/steps/workflow-scm-step/

The checkout steps provides an option to update all submodules and can even update the submodules recursively, e.g.:

checkout([$class: 'GitSCM',
    branches: [[name: '*/master']],
    doGenerateSubmoduleConfigurations: false,
    extensions: [[$class: 'SubmoduleOption',
        disableSubmodules: false,
        parentCredentials: false,
        recursiveSubmodules: false,
        reference: '',
        trackingSubmodules: false
    ]],
    submoduleCfg: [],
    userRemoteConfigs: [[url: 'ssh://myserver/myrepo']]
])

What actually enables cloning of the submodules is the SubmoduleOption extension as seen in the example above.

As the syntax is - let's say - little bit more complex I recommend using the snipped generator. 


from: https://stackoverflow.com/questions/51361907/implicitly-loading-submodules-in-jenkins-pipeline-stages

2021年7月28日 星期三

Get the current commit id of specified submodule

 You can start with git ls-files -s (as in this answer)

cd /path/to/parent/repo
git ls-files -s yourSubmodule


from: https://stackoverflow.com/questions/32327108/get-the-current-commit-id-of-specified-submodule

How to get the last commit ID of a remote repo using curl-like command?

 git log --format="%H" -n 1


from: https://stackoverflow.com/questions/19176359/how-to-get-the-last-commit-id-of-a-remote-repo-using-curl-like-command

2021年7月27日 星期二

using “git submodule foreach” can you skip a list of submodules?

 lets say I have 10 submoules:

module/1
module/2
module/3
module/4
module/5
module/6
module/7
module/8
module/9
module/10

so use the shell:

 git submodule foreach 'case $name in 4|6|7) git status ;; *) git status ;; esac'

from: https://stackoverflow.com/questions/58291315/using-git-submodule-foreach-can-you-skip-a-list-of-submodules

Check if git submodule has been updated on remote

 Based on https://stackoverflow.com/a/3278427/7976758 I'd do something like this:

git submodule foreach git remote update
git submodule foreach git --no-pager diff origin/master master

If submodules use different branches the script needs to take that into account.


from: https://stackoverflow.com/questions/50965094/check-if-git-submodule-has-been-updated-on-remote

2021年5月14日 星期五

Git - how to find first commit of specific branch

 git log master..branch --oneline | tail -1

Where "branch" is your specific branch name. The dot-dot gives you all of the commits that the branch has that master doesn't have. tail -1 returns the last line from the previous output.


from : https://stackoverflow.com/questions/18407526/git-how-to-find-first-commit-of-specific-branch

2021年3月3日 星期三

How do I rename both a Git local and remote branch name?

 If you have named a branch incorrectly AND pushed this to the remote repository follow these steps to rename that branch (based on this article):

  1. Rename your local branch:

    • If you are on the branch you want to rename:
      git branch -m new-name

    • If you are on a different branch:
      git branch -m old-name new-name

  2. Delete the old-name remote branch and push the new-name local branch:
    git push origin :old-name new-name

  3. Reset the upstream branch for the new-name local branch:
    Switch to the branch and then:
    git push origin -u new-name


from : https://stackoverflow.com/questions/30590083/how-do-i-rename-both-a-git-local-and-remote-branch-name