From ad208a544b82a2c4bed3a2e9f676bdf1dc57feb2 Mon Sep 17 00:00:00 2001 From: Naoto Ono Date: Fri, 2 Aug 2024 14:15:21 +0900 Subject: [PATCH 1/4] Track shallow cloned repository --- launchable/commands/record/commit.py | 18 +++++++++++++++++- launchable/utils/tracking.py | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/launchable/commands/record/commit.py b/launchable/commands/record/commit.py index 364cbd30..c8b47e10 100644 --- a/launchable/commands/record/commit.py +++ b/launchable/commands/record/commit.py @@ -74,8 +74,24 @@ def commit(ctx, source: str, executable: bool, max_days: int, scrub_pii: bool, i ) client.print_exception_and_recover(e) + cwd = os.path.abspath(source) try: - exec_jar(os.path.abspath(source), max_days, ctx.obj, is_collect_message) + is_shallow = subprocess.check_output( + ['git', 'rev-parse', '--is-shallow-repository'], + stderr=subprocess.DEVNULL, + cwd=cwd, + universal_newlines=True).strip() + if is_shallow == "true": + click.echo(click.style( + "Can't collect commit history from {} since it is the shallow repository. " + "Please use full clone or disable commit collection by --no-commit-collection option." + .format(cwd), + fg='red'), + err=True) + tracking_client.send_event( + event_name=Tracking.Event.SHALLOW_CLONE + ) + exec_jar(cwd, max_days, ctx.obj, is_collect_message) except Exception as e: if os.getenv(REPORT_ERROR_KEY): raise e diff --git a/launchable/utils/tracking.py b/launchable/utils/tracking.py index 376b4596..01231657 100644 --- a/launchable/utils/tracking.py +++ b/launchable/utils/tracking.py @@ -12,7 +12,7 @@ class Tracking: # General events class Event(Enum): - SHALLOW_CLONE = 'shallow_clone' # this event is an example + SHALLOW_CLONE = 'SHALLOW_CLONE' # this event is an example # Error events class ErrorEvent(Enum): From b5ceeb0327da3d070401bba3ecbdd25f11d7bcaa Mon Sep 17 00:00:00 2001 From: Naoto Ono Date: Fri, 2 Aug 2024 14:16:34 +0900 Subject: [PATCH 2/4] Refactor --- launchable/commands/record/commit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launchable/commands/record/commit.py b/launchable/commands/record/commit.py index c8b47e10..03684481 100644 --- a/launchable/commands/record/commit.py +++ b/launchable/commands/record/commit.py @@ -99,7 +99,7 @@ def commit(ctx, source: str, executable: bool, max_days: int, scrub_pii: bool, i click.echo(click.style( "Can't get commit history from `{}`. Do you run command root of git-controlled directory? " "If not, please set a directory use by --source option." - .format(os.path.abspath(source)), + .format(cwd), fg='yellow'), err=True) print(e) From 58c45aec060d77cda60d8e33016314bc92a63f35 Mon Sep 17 00:00:00 2001 From: Naoto Ono Date: Mon, 5 Aug 2024 09:57:43 +0900 Subject: [PATCH 3/4] Refactor the logic --- launchable/commands/record/commit.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/launchable/commands/record/commit.py b/launchable/commands/record/commit.py index 03684481..ba696d42 100644 --- a/launchable/commands/record/commit.py +++ b/launchable/commands/record/commit.py @@ -86,11 +86,17 @@ def commit(ctx, source: str, executable: bool, max_days: int, scrub_pii: bool, i "Can't collect commit history from {} since it is the shallow repository. " "Please use full clone or disable commit collection by --no-commit-collection option." .format(cwd), - fg='red'), + fg='yellow'), err=True) tracking_client.send_event( event_name=Tracking.Event.SHALLOW_CLONE ) + except Exception as e: + if os.getenv(REPORT_ERROR_KEY): + raise e + else: + print(e) + try: exec_jar(cwd, max_days, ctx.obj, is_collect_message) except Exception as e: if os.getenv(REPORT_ERROR_KEY): From 235df8960bb1333eac629d902008e822ab010f66 Mon Sep 17 00:00:00 2001 From: Naoto Ono Date: Tue, 6 Aug 2024 09:44:25 +0900 Subject: [PATCH 4/4] Fix some nits --- launchable/commands/record/commit.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/launchable/commands/record/commit.py b/launchable/commands/record/commit.py index ba696d42..6e24920f 100644 --- a/launchable/commands/record/commit.py +++ b/launchable/commands/record/commit.py @@ -82,12 +82,6 @@ def commit(ctx, source: str, executable: bool, max_days: int, scrub_pii: bool, i cwd=cwd, universal_newlines=True).strip() if is_shallow == "true": - click.echo(click.style( - "Can't collect commit history from {} since it is the shallow repository. " - "Please use full clone or disable commit collection by --no-commit-collection option." - .format(cwd), - fg='yellow'), - err=True) tracking_client.send_event( event_name=Tracking.Event.SHALLOW_CLONE ) @@ -103,7 +97,7 @@ def commit(ctx, source: str, executable: bool, max_days: int, scrub_pii: bool, i raise e else: click.echo(click.style( - "Can't get commit history from `{}`. Do you run command root of git-controlled directory? " + "Couldn't get commit history from `{}`. Do you run command root of git-controlled directory? " "If not, please set a directory use by --source option." .format(cwd), fg='yellow'),