diff --git a/contribute.py b/contribute.py index 0bb6202fdd..c04f64a75f 100755 --- a/contribute.py +++ b/contribute.py @@ -27,9 +27,14 @@ def main(def_args=sys.argv[1:]): days_after = args.days_after if days_after < 0: sys.exit('days_after must not be negative') - os.mkdir(directory) + if os.path.exists(directory): + print('Directory already exists, continuing in existing repository...') + else: + os.mkdir(directory) os.chdir(directory) - run(['git', 'init', '-b', 'main']) + + if not os.path.exists('.git'): + run(['git', 'init', '-b', 'main']) if user_name is not None: run(['git', 'config', 'user.name', user_name]) @@ -38,16 +43,26 @@ def main(def_args=sys.argv[1:]): run(['git', 'config', 'user.email', user_email]) start_date = curr_date.replace(hour=20, minute=0) - timedelta(days_before) - for day in (start_date + timedelta(n) for n - in range(days_before + days_after)): + days = list(start_date + timedelta(n) for n in range(days_before + days_after)) + total = len(days) + for i, day in enumerate(days): + print('\rGenerating commits... %d/%d' % (i + 1, total), end='', flush=True) if (not no_weekends or day.weekday() < 5) \ and randint(0, 100) < frequency: for commit_time in (day + timedelta(minutes=m) for m in range(contributions_per_day(args))): contribute(commit_time) + print() if repository is not None: - run(['git', 'remote', 'add', 'origin', repository]) + existing_remotes = [] + try: + from subprocess import check_output + existing_remotes = check_output(['git', 'remote']).decode().split() + except Exception: + pass + if 'origin' not in existing_remotes: + run(['git', 'remote', 'add', 'origin', repository]) run(['git', 'branch', '-M', 'main']) run(['git', 'push', '-u', 'origin', 'main'])