Skip to content

Commit bffe71f

Browse files
Emil Medvegitster
authored andcommitted
git-submodule: Instead of using only annotated tags, use any tags.
Some repositories might not use/have annotated tags (for example the ones created with git-cvsimport) and git-submodule status might fail because git-describe might fail to find a tag. This change allows the status of a submodule to be described/displayed relative to lightweight tags as well. Signed-off-by: Emil Medve <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ecda072 commit bffe71f

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

git-submodule.sh

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,18 @@ modules_update()
199199
done
200200
}
201201

202+
set_name_rev () {
203+
revname=$( (
204+
unset GIT_DIR &&
205+
cd "$1" && {
206+
git-describe "$2" 2>/dev/null ||
207+
git-describe --tags "$2" 2>/dev/null ||
208+
git-describe --contains --tags "$2"
209+
}
210+
) )
211+
test -z "$revname" || revname=" ($revname)"
212+
}
213+
202214
#
203215
# List all submodules, prefixed with:
204216
# - submodule not initialized
@@ -221,17 +233,18 @@ modules_list()
221233
say "-$sha1 $path"
222234
continue;
223235
fi
224-
revname=$(unset GIT_DIR && cd "$path" && git-describe $sha1)
236+
revname=$(unset GIT_DIR && cd "$path" && git-describe --tags $sha1)
237+
set_name_rev "$path" $"sha1"
225238
if git diff-files --quiet -- "$path"
226239
then
227-
say " $sha1 $path ($revname)"
240+
say " $sha1 $path$revname"
228241
else
229242
if test -z "$cached"
230243
then
231244
sha1=$(unset GIT_DIR && cd "$path" && git-rev-parse --verify HEAD)
232-
revname=$(unset GIT_DIR && cd "$path" && git-describe $sha1)
245+
set_name_rev "$path" $"sha1"
233246
fi
234-
say "+$sha1 $path ($revname)"
247+
say "+$sha1 $path$revname"
235248
fi
236249
done
237250
}

0 commit comments

Comments
 (0)