Skip to content

Commit af5936f

Browse files
committed
Go back to the original branch after pylint check
Previously we save the current commit hash before running lintstack. This is no problem for Jenkins but not very friendly if we run lintstack locally. Every time after it's done, git is in detached HEAD mode. This patch remembers the current branch name and automatically go back to the branch if available. Otherwise we fall back to the commit hash. Part of blueprint lintstack Change-Id: I145df3027022fc9a8302bc6da9ab300f677f3386
1 parent 52fe25a commit af5936f

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

tools/lintstack.sh

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,16 @@
2020
# commit for review.
2121
set -e
2222
TOOLS_DIR=$(cd $(dirname "$0") && pwd)
23-
GITHEAD=`git rev-parse HEAD`
23+
# Get the current branch name.
24+
GITHEAD=`git rev-parse --abbrev-ref HEAD`
25+
if [[ "$GITHEAD" == "HEAD" ]]; then
26+
# In detached head mode, get revision number instead
27+
GITHEAD=`git rev-parse HEAD`
28+
echo "Currently we are at commit $GITHEAD"
29+
else
30+
echo "Currently we are at branch $GITHEAD"
31+
fi
32+
2433
cp -f $TOOLS_DIR/lintstack.py $TOOLS_DIR/lintstack.head.py
2534

2635
if git rev-parse HEAD^2 2>/dev/null; then
@@ -47,8 +56,4 @@ git checkout $GITHEAD
4756
$TOOLS_DIR/lintstack.head.py
4857
echo "Check passed. FYI: the pylint exceptions are:"
4958
cat $TOOLS_DIR/pylint_exceptions
50-
echo
51-
echo "You are in detached HEAD mode. If you are a developer"
52-
echo "and not very familiar with git, you might want to do"
53-
echo "'git checkout branch-name' to go back to your branch."
5459

0 commit comments

Comments
 (0)