gcc/contrib/git-fetch-vendor.sh

67 lines
1.8 KiB
Bash
Raw Normal View History

#!/bin/sh
contrib: New remotes structure for vendor and personal refs The initial structure for vendor and personal branches makes use of the default remote (normally origin) for the upstream repository). Unfortunately, this causes some confusion, especially for personal branches because a push will not push to the correct upstream location. This can be 'fixed' by adding a push refspec for the remote, but that has the unfortunate consequence of breaking the push.default behaviour for git push, and it becomes too easy to accidentally commit something unintended to the main parts of the repository. To work around this, this patch changes the configuration to use separate 'remotes' for these additional refs, with one remote for the personal space and another remote for each vendor's space. The personal space is called after the user's preferred branch-space prefix (default 'me'), the vendor spaces are called vendors/<vendor-name>. As far as possible, I've made the script automatically restructure any existing fetch or push lines that earlier versions of the scripts may have created - the gcc-git-customization.sh script will convert all vendor refs that it can find, so it is not necessary to re-add any vendors you've already added. You might, however, want to run git remote prune <origin> after running to clean up any stale upstream-refs that might still be in your local repo, and then git fetch vendors/<vendor> or git fetch <me> to re-populate the remotes/ structures. Also, for any branch you already have that tracks a personal or vendor branch upstream, you might need to run git config branch.<name>.remote <new-remote> so that merges and pushes go to the right place (I haven't attempted to automate this last part). For vendors, the new structure means that git checkout -b <vendor>/<branch> remotes/vendors/<vendor>/<branch> will correctly set up a remote tracking branch. Please be aware that if you have multiple personal branches set up, then git push <me> will still consider all of them for pushing. If you only want to push one branch, then either write git push <me> HEAD or git push <me> <me>/branch as appropriate. And don't forget '-n' (--dry-run) to see what would be done if this were not a dry run. Finally, now that the vendors spaces are isolated from each other and from the other spaces, I've added an option "--enable-push" to git-fetch-vendor.sh. If passed, then a "push" spec will be added for that vendor to enable pushing to the upstream. If you re-run the script for the same vendor without the option, the push spec will be removed. * gcc-git-customization.sh: Check that user-supplied remote name exists before continuting. Use a separate remotes for the personal commit area. Convert existing personal and vendor fetch rules to new layout. * git-fetch-vendor.sh: New vendor layout. Add --enable-push option.
2020-01-20 10:37:29 +00:00
usage ()
{
echo "Usage: $0 [--enable-push] <vendor>"
echo "The following vendors are already known:"
git ls-remote ${upstream} "*/vendors/*" | sed -r "s:.*/vendors/([^/]+)/.*:\1:"|sort|uniq
exit 1
contrib: New remotes structure for vendor and personal refs The initial structure for vendor and personal branches makes use of the default remote (normally origin) for the upstream repository). Unfortunately, this causes some confusion, especially for personal branches because a push will not push to the correct upstream location. This can be 'fixed' by adding a push refspec for the remote, but that has the unfortunate consequence of breaking the push.default behaviour for git push, and it becomes too easy to accidentally commit something unintended to the main parts of the repository. To work around this, this patch changes the configuration to use separate 'remotes' for these additional refs, with one remote for the personal space and another remote for each vendor's space. The personal space is called after the user's preferred branch-space prefix (default 'me'), the vendor spaces are called vendors/<vendor-name>. As far as possible, I've made the script automatically restructure any existing fetch or push lines that earlier versions of the scripts may have created - the gcc-git-customization.sh script will convert all vendor refs that it can find, so it is not necessary to re-add any vendors you've already added. You might, however, want to run git remote prune <origin> after running to clean up any stale upstream-refs that might still be in your local repo, and then git fetch vendors/<vendor> or git fetch <me> to re-populate the remotes/ structures. Also, for any branch you already have that tracks a personal or vendor branch upstream, you might need to run git config branch.<name>.remote <new-remote> so that merges and pushes go to the right place (I haven't attempted to automate this last part). For vendors, the new structure means that git checkout -b <vendor>/<branch> remotes/vendors/<vendor>/<branch> will correctly set up a remote tracking branch. Please be aware that if you have multiple personal branches set up, then git push <me> will still consider all of them for pushing. If you only want to push one branch, then either write git push <me> HEAD or git push <me> <me>/branch as appropriate. And don't forget '-n' (--dry-run) to see what would be done if this were not a dry run. Finally, now that the vendors spaces are isolated from each other and from the other spaces, I've added an option "--enable-push" to git-fetch-vendor.sh. If passed, then a "push" spec will be added for that vendor to enable pushing to the upstream. If you re-run the script for the same vendor without the option, the push spec will be removed. * gcc-git-customization.sh: Check that user-supplied remote name exists before continuting. Use a separate remotes for the personal commit area. Convert existing personal and vendor fetch rules to new layout. * git-fetch-vendor.sh: New vendor layout. Add --enable-push option.
2020-01-20 10:37:29 +00:00
}
# Should we insert a "push" refspec to enable pushing to the vendor branch?
enable_push=no
upstream=`git config --get "gcc-config.upstream"`
if [ x"$upstream" = x ]
then
echo "Config gcc-config.upstream not set, run contrib/gcc-git-customization.sh"
exit 1
fi
contrib: New remotes structure for vendor and personal refs The initial structure for vendor and personal branches makes use of the default remote (normally origin) for the upstream repository). Unfortunately, this causes some confusion, especially for personal branches because a push will not push to the correct upstream location. This can be 'fixed' by adding a push refspec for the remote, but that has the unfortunate consequence of breaking the push.default behaviour for git push, and it becomes too easy to accidentally commit something unintended to the main parts of the repository. To work around this, this patch changes the configuration to use separate 'remotes' for these additional refs, with one remote for the personal space and another remote for each vendor's space. The personal space is called after the user's preferred branch-space prefix (default 'me'), the vendor spaces are called vendors/<vendor-name>. As far as possible, I've made the script automatically restructure any existing fetch or push lines that earlier versions of the scripts may have created - the gcc-git-customization.sh script will convert all vendor refs that it can find, so it is not necessary to re-add any vendors you've already added. You might, however, want to run git remote prune <origin> after running to clean up any stale upstream-refs that might still be in your local repo, and then git fetch vendors/<vendor> or git fetch <me> to re-populate the remotes/ structures. Also, for any branch you already have that tracks a personal or vendor branch upstream, you might need to run git config branch.<name>.remote <new-remote> so that merges and pushes go to the right place (I haven't attempted to automate this last part). For vendors, the new structure means that git checkout -b <vendor>/<branch> remotes/vendors/<vendor>/<branch> will correctly set up a remote tracking branch. Please be aware that if you have multiple personal branches set up, then git push <me> will still consider all of them for pushing. If you only want to push one branch, then either write git push <me> HEAD or git push <me> <me>/branch as appropriate. And don't forget '-n' (--dry-run) to see what would be done if this were not a dry run. Finally, now that the vendors spaces are isolated from each other and from the other spaces, I've added an option "--enable-push" to git-fetch-vendor.sh. If passed, then a "push" spec will be added for that vendor to enable pushing to the upstream. If you re-run the script for the same vendor without the option, the push spec will be removed. * gcc-git-customization.sh: Check that user-supplied remote name exists before continuting. Use a separate remotes for the personal commit area. Convert existing personal and vendor fetch rules to new layout. * git-fetch-vendor.sh: New vendor layout. Add --enable-push option.
2020-01-20 10:37:29 +00:00
case $# in
1)
# vendor names never start with -, so catch this in case user wrote something like --help.
case "$1" in
-*)
usage
;;
*)
vendor=$1
;;
esac
;;
2)
vendor=$2
if [ "$1" = "--enable-push" ]
then
enable_push=yes
else
usage
fi
;;
*)
usage
;;
esac
echo "setting up git to fetch vendor ${vendor} to remotes/vendors/${vendor}"
url=$(git config --get "remote.${upstream}.url")
pushurl=$(git config --get "remote.${upstream}.pushurl")
git config "remote.vendors/${vendor}.url" "${url}"
if [ "x$pushurl" != "x" ]
then
git config "remote.vendors/${vendor}.pushurl" "${pushurl}"
fi
git config --replace-all "remote.vendors/${vendor}.fetch" "+refs/vendors/${vendor}/heads/*:refs/remotes/vendors/${vendor}/*" "refs/vendors/${vendor}/heads"
git config --replace-all "remote.vendors/${vendor}.fetch" "+refs/vendors/${vendor}/tags/*:refs/tags/vendors/${vendor}/*" "refs/vendors/${vendor}/tags"
if [ "$enable_push" = "yes" ]
then
echo "Warning: take care when pushing that you only push the changes you intend."
echo "E.g. use \"git push vendors/${vendor} HEAD\" to push the current branch"
git config --replace-all "remote.vendors/${vendor}.push" "refs/heads/${vendor}/*:refs/vendors/${vendor}/heads/*"
else
git config --unset-all "remote.vendors/${vendor}.push"
fi
git fetch vendors/${vendor}