Browse Source

[git] shellcheck, minor changes

Matteo Cypriani 9 months ago
parent
commit
81b60c133a
4 changed files with 35 additions and 20 deletions
  1. 4
    4
      git/git-changelog
  2. 10
    7
      git/git-cherry-move
  3. 11
    4
      git/git-merge-ff-only
  4. 10
    5
      git/git-tag-update

+ 4
- 4
git/git-changelog View File

@@ -43,21 +43,21 @@ if [ "$HEADER" != "" ] ; then
43 43
 fi
44 44
 
45 45
 for TAG in $(git tag -l | sort -r) ; do
46
-	if echo $TAG | egrep '^v[0-9]+(\.[0-9]+)+$' >/dev/null ; then
46
+	if echo "$TAG" | grep -Eq '^v[0-9]+(\.[0-9]+)+$' ; then
47 47
 		# Display current tag's name
48
-		echo $TAG >&2
48
+		echo "$TAG" >&2
49 49
 
50 50
 		# Print empty lines if needed
51 51
 		if [ $PRINTNL -eq 1 ] ; then
52 52
 			i=0
53 53
 			while [ $i -lt $NEWLINES ] ; do
54 54
 				echo
55
-				i=`expr $i + 1`
55
+				i=$((i + 1))
56 56
 			done
57 57
 		fi
58 58
 
59 59
 		# Print the tag message
60
-		git tag -l $TAG -n$NBLINES | sed 's/ \+$//'
60
+		git tag -l "$TAG" -n$NBLINES | sed 's/ \+$//'
61 61
 
62 62
 		PRINTNL=1
63 63
 	else

+ 10
- 7
git/git-cherry-move View File

@@ -11,9 +11,16 @@
11 11
 # This script moves a commit from a branch head to another. It is
12 12
 # the equivalent of git cherry-pick followed by git reset.
13 13
 
14
-
15 14
 set -e
16 15
 
16
+USAGE=$(cat <<EOF
17
+Usage:
18
+  $0 <src-branch> <dst-branch> [ reset-arg ]
19
+
20
+'reset-arg' is passed to the final reset (can be --hard for example).
21
+EOF
22
+)
23
+
17 24
 assert_branch_exists()
18 25
 {
19 26
 	if ! git for-each-ref refs/heads | grep "/${1}$" >/dev/null ; then
@@ -23,14 +30,10 @@ assert_branch_exists()
23 30
 }
24 31
 
25 32
 if [ $# -lt 2 ] ; then
26
-	echo "Usage:"
27
-	echo "  $0 <src-branch> <dst-branch> [ reset-arg ]"
28
-	echo -n "'reset-arg' is passed to the final reset"
29
-	echo    " (can be --hard for example)."
33
+	printf '%s\n' "$USAGE" >&2
30 34
 	exit 1
31 35
 fi
32 36
 
33
-
34 37
 assert_branch_exists "$1"
35 38
 SRC="$1"
36 39
 shift
@@ -43,4 +46,4 @@ shift
43 46
 git checkout "$DST"
44 47
 git cherry-pick "$SRC"
45 48
 git checkout "$SRC"
46
-git reset $1 HEAD^
49
+git reset "$1" HEAD^

+ 11
- 4
git/git-merge-ff-only View File

@@ -16,9 +16,16 @@
16 16
 
17 17
 set -e
18 18
 
19
+USAGE=$(cat <<EOF
20
+Usage:
21
+  $0 <main_branch> <topic_branch>"
22
+
23
+<main_branch> will be fast-forwarded to <topic_branch> if possible."
24
+EOF
25
+)
26
+
19 27
 if [ $# -ne 2 ] ; then
20
-	echo "Usage: $0 <main_branch> <topic_branch>"
21
-	echo "<main_branch> will be fast-forwarded to <topic_branch> if possible."
28
+	printf '%s\n' "$USAGE" >&2
22 29
 	exit 1
23 30
 fi
24 31
 
@@ -29,10 +36,10 @@ echo "Trying to merge $TOPIC_BRANCH into $MAIN_BRANCH..."
29 36
 
30 37
 DIFF="$(git rev-list "$TOPIC_BRANCH".."$MAIN_BRANCH")"
31 38
 if [ -z "$DIFF" ] ; then
32
-	echo "$TOPIC_BRANCH contains all the commits of $MAIN_BRANCH."
39
+	echo -- "$TOPIC_BRANCH contains all the commits of $MAIN_BRANCH."
33 40
 	echo "Fast-forwarding $MAIN_BRANCH to $TOPIC_BRANCH."
34 41
 	git branch -f "$MAIN_BRANCH" "$TOPIC_BRANCH"
35 42
 else
36
-	echo "$TOPIC_BRANCH does not contain all the commits of $MAIN_BRANCH."
43
+	echo -- "$TOPIC_BRANCH does not contain all the commits of $MAIN_BRANCH."
37 44
 	echo "Fast-forward impossible, aborting."
38 45
 fi

+ 10
- 5
git/git-tag-update View File

@@ -17,16 +17,21 @@ set -e
17 17
 #set -x
18 18
 
19 19
 if [ $# -ne 1 ] ; then
20
-	echo "Usage: $0 <tag-name>"
20
+	echo "Usage: $0 <tag-name>" >&2
21 21
 	exit 1
22 22
 fi
23 23
 
24
-TAG=$1
24
+commiter_date()
25
+{
26
+	git tag -v "$TAG" 2>/dev/null | grep ^tagger | cut -f5- -d' '
27
+}
25 28
 
26
-GIT_COMMITTER_DATE="$(git tag -v $TAG 2>/dev/null|grep ^tagger | cut -f5- -d' ')"
29
+TAG="$1"
30
+
31
+GIT_COMMITTER_DATE="$(commiter_date)"
27 32
 export GIT_COMMITTER_DATE
28
-git tag -sf $TAG $TAG
33
+git tag -sf "$TAG" "$TAG"
29 34
 
30 35
 echo "Old tag commiter date: $GIT_COMMITTER_DATE"
31
-GIT_COMMITTER_DATE="$(git tag -v $TAG 2>/dev/null|grep ^tagger | cut -f5- -d' ')"
36
+GIT_COMMITTER_DATE="$(commiter_date)"
32 37
 echo "New tag commiter date: $GIT_COMMITTER_DATE"

Loading…
Cancel
Save