Browse Source

Bugfix: ignore names that were removed and re-added with a new name

If a vendor repo is removed under one name and re-added under a
different name, *both* names would be listed and accepted as
vendor names.

For example:
  $ git vendor add mispeled http://some/url
  $ git vendor remove mispeled
  $ git vendor add correct http://some/url
  $ git vendor list
  correct:
  mispeled:

To fix, validate each vendor name by identifying the most recent
vendor name associated with the subtree directory.
pull/18/head
Andrew Hastings 5 years ago
committed by Andrew Hastings
parent
commit
9d3deac361
1 changed files with 44 additions and 5 deletions
  1. +44
    -5
      bin/git-vendor

+ 44
- 5
bin/git-vendor View File

@ -37,6 +37,12 @@ if [ "$1" = "--prefix" ]; then
shift; shift shift; shift
fi fi
# Simulate an associative array (for older versions of bash)
var_name()
{
echo -n "name_$1" | tr -c '[A-Za-z0-9]' '_'
}
vendor_names_from_log() vendor_names_from_log()
{ {
name= name=
@ -50,8 +56,11 @@ vendor_names_from_log()
git-vendor-dir:) dir="$b" ;; git-vendor-dir:) dir="$b" ;;
END) END)
# Only consider dependencies which still exist on disk # Only consider dependencies which still exist on disk
if [ -d "$dir" ]; then
# and haven't been renamed
eval `echo -n val='$'$(var_name "$dir")`
if [ -d "$dir" -a -z "$val" ]; then
echo "$name" echo "$name"
eval `echo -n $(var_name "$dir")=1`
fi fi
name= name=
dir= dir=
@ -60,12 +69,30 @@ vendor_names_from_log()
done | sort -u done | sort -u
} }
vendor_git_log_first()
vendor_git_log_from_name()
{ {
name="$1" name="$1"
git log -1 --grep="^git-vendor-name: $name\$" --pretty=format:'START %H%n%s%n%n%b%nEND%n' HEAD git log -1 --grep="^git-vendor-name: $name\$" --pretty=format:'START %H%n%s%n%n%b%nEND%n' HEAD
} }
vendor_name_from_dir()
{
name=
dir="$1"
git log -1 --grep="^git-vendor-dir: $dir\$" --pretty=format:'START %H%n%s%n%n%b%nEND%n' HEAD |
while read a b junk; do
case "$a" in
git-vendor-name:) name="$b" ;;
END)
if [ -n "$name" ]; then
echo "$name"
fi
name=
;;
esac
done
}
cmd_add() cmd_add()
{ {
require_clean_work_tree require_clean_work_tree
@ -98,7 +125,7 @@ cmd_list()
showOnly="$1" showOnly="$1"
for name in $(vendor_names_from_log); for name in $(vendor_names_from_log);
do do
vendor_git_log_first "$name" |
vendor_git_log_from_name "$name" |
while read a b junk; do while read a b junk; do
case "$a" in case "$a" in
START) commit="$b" ;; START) commit="$b" ;;
@ -142,7 +169,7 @@ cmd_update()
if [ $# -lt 1 ]; then if [ $# -lt 1 ]; then
die "Incorrect options provided: git vendor update <name> [<ref>]" die "Incorrect options provided: git vendor update <name> [<ref>]"
fi fi
vendor_git_log_first "$name" |
vendor_git_log_from_name "$name" |
while read a b junk; do while read a b junk; do
case "$a" in case "$a" in
START) ;; START) ;;
@ -154,6 +181,12 @@ cmd_update()
die "Dependency \"$1\" is missing from \"$dir\"" die "Dependency \"$1\" is missing from \"$dir\""
fi fi
# And hasn't been renamed
logname=$(vendor_name_from_dir "$dir")
if [ "$name" != "$logname" ]; then
die "Dependency \"$1\" was renamed \"$logname\""
fi
if [ ! -z "$repository" ]; if [ ! -z "$repository" ];
then then
message="\ message="\
@ -179,7 +212,7 @@ cmd_remove()
if [ $# -lt 1 ]; then if [ $# -lt 1 ]; then
die "Incorrect options provided: git vendor remove <name>" die "Incorrect options provided: git vendor remove <name>"
fi fi
vendor_git_log_first "$name" |
vendor_git_log_from_name "$name" |
while read a b junk; do while read a b junk; do
case "$a" in case "$a" in
START) ;; START) ;;
@ -189,6 +222,12 @@ cmd_remove()
if [ ! -d "$dir" ]; then if [ ! -d "$dir" ]; then
die "Dependency \"$1\" is missing from \"$dir\"" die "Dependency \"$1\" is missing from \"$dir\""
fi fi
# And hasn't been renamed
logname=$(vendor_name_from_dir "$dir")
if [ "$name" != "$logname" ]; then
die "Dependency \"$1\" was renamed \"$logname\""
fi
git rm -rf "$dir" git rm -rf "$dir"
git commit --message "Removing \"$name\" from \"$dir\"" git commit --message "Removing \"$name\" from \"$dir\""
break break


Loading…
Cancel
Save