Skip to content

Commit

Permalink
read default email from gitconfig
Browse files Browse the repository at this point in the history
Summary:
check standard git configuration hierarchy for presence of a
kaclone.email setting, and if so use that as the default instead of
inferring based on environment

Reviewers: csilvers

Reviewed By: csilvers

Subscribers: alpert

Projects: #devenvfixup

Differential Revision: https://phabricator.khanacademy.org/D18650
  • Loading branch information
Matthew Rothenberg committed Jun 17, 2015
1 parent 151d7c9 commit 9c6c7c0
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions bin/ka-clone
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import shutil
import subprocess
import sys

DEFAULT_EMAIL = os.environ['USER'] + "@khanacademy.org"
DEFAULT_EMAIL_DOMAIN = "khanacademy.org"
TEMPLATES_DIR = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
os.path.pardir,
Expand Down Expand Up @@ -50,7 +50,7 @@ def _cli_parser():
# default values
parser.add_argument('--email',
help="email address to use (default: %(default)s)",
default=DEFAULT_EMAIL)
default=_default_email())
# preferences
parser.add_argument('-q', '--quiet',
action='store_true',
Expand Down Expand Up @@ -80,7 +80,14 @@ def die_if_not_valid_git_repo():
sys.exit(revparse_retcode)


def set_email(email=DEFAULT_EMAIL):
def _default_email():
try:
return subprocess.check_output(["git", "config", "kaclone.email"])
except subprocess.CalledProcessError:
return os.environ['USER'] + "@" + DEFAULT_EMAIL_DOMAIN


def set_email(email=_default_email()):
subprocess.check_call(
['git', 'config', '--local', 'user.email', email]
)
Expand Down

0 comments on commit 9c6c7c0

Please sign in to comment.