diff --git a/gitconfig b/gitconfig index 44dabc8..facd56a 100644 --- a/gitconfig +++ b/gitconfig @@ -1,6 +1,8 @@ -[user] - email = unknown@unknown.com - name = Unknown User +# NOTE: deliberately no [user] section. This file is copied over +# ~/.gitconfig on every run, so hard-coding an identity here silently +# replaces the real one on every machine it is installed to. setup_git +# preserves whatever identity is already configured, or takes it from +# GIT_USER_NAME / GIT_USER_EMAIL. [color] diff = auto diff --git a/setup b/setup index df939ed..31c3756 100755 --- a/setup +++ b/setup @@ -216,7 +216,39 @@ setup_ssh() { setup_git() { install_package git git-lfs - get_prestobuntu_file gitconfig $HOME/.gitconfig + + # ~/.gitconfig is overwritten wholesale below, so capture any + # identity already configured and put it back afterwards. Ignore the + # old placeholder, which earlier versions of this script installed. + local name email + name=$(git config --global --get user.name || true) + email=$(git config --global --get user.email || true) + if [[ $name == "Unknown User" ]]; then + name="" + fi + if [[ $email == "unknown@unknown.com" ]]; then + email="" + fi + + get_prestobuntu_file gitconfig "$HOME/.gitconfig" + + # An explicit setting wins over whatever was there before. These may + # be exported, or set in config.local once that mechanism lands. + name=${GIT_USER_NAME:-$name} + email=${GIT_USER_EMAIL:-$email} + + if [[ -n $name ]]; then + git config --global user.name "$name" + fi + if [[ -n $email ]]; then + git config --global user.email "$email" + fi + + if [[ -z $name || -z $email ]]; then + info "git identity not set; run:" + info " git config --global user.name 'Your Name'" + info " git config --global user.email 'you@example.com'" + fi } get_internet_file() {