From db8aaf5f8f0886c8aad9abfc504685e49e70b39c Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Thu, 23 Nov 2017 10:27:30 -0200 Subject: Adds git-submodule-checkout-branch and git-submodules-checkout-branches --- git-submodule-checkout-branch | 33 +++++++++++++++++++++++++++++++++ git-submodules-checkout-branches | 7 +++++++ 2 files changed, 40 insertions(+) create mode 100755 git-submodule-checkout-branch create mode 100755 git-submodules-checkout-branches diff --git a/git-submodule-checkout-branch b/git-submodule-checkout-branch new file mode 100755 index 0000000..6613bf4 --- /dev/null +++ b/git-submodule-checkout-branch @@ -0,0 +1,33 @@ +#!/bin/bash +# +# Checkout branche a submodule. +# + +# Parameters +BASENAME="`basename $0`" + +# Checkout the branch containing a commit +function checkout_branch { + # Check if we are in a detached HEAD + if git branch | grep -q '* (HEAD detached'; then + # Determine the commit we're in + local commit="`git log -n 1 | head -1 | cut -d ' ' -f 2`" + + # Get the first remote branch that contains our commit + # + # In the future some criteria might be stablished to determine how to decide + # if the comment is present in more than one branch. Which one to prioritize? + # A topic branch in the form of "feature/"? The "develop" branch? + local branch="`git branch -r --contains $commit 2> /dev/null | grep -v 'HEAD' | head -1 | sed -e 's|^[^/]*/||'`" + + # Checkout to the given commit + if [ ! -z "$branch" ]; then + git checkout $branch + else + echo "$BASENAME: no such branch containing dangling commit $commit" + fi + fi +} + +# Dispatch +checkout_branch diff --git a/git-submodules-checkout-branches b/git-submodules-checkout-branches new file mode 100755 index 0000000..f254ca9 --- /dev/null +++ b/git-submodules-checkout-branches @@ -0,0 +1,7 @@ +#!/bin/bash +# +# Checkout branches in all submodules, recursivelly. +# + +# Run recursivelly for each submodule +git submodule foreach --recursive git-submodule-checkout-branch -- cgit v1.2.3