44from getpass import getpass
55import json
66import requests
7+ import subprocess
78import sys
89
10+ def has_uncommitted_changes ():
11+ """Check if there are uncommitted changes in a jj or git repository."""
12+ # Try jj first — works for both native jj repos and git-backed jj repos.
13+ try :
14+ result = subprocess .run (
15+ ["jj" , "diff" , "--stat" ],
16+ capture_output = True ,
17+ text = True ,
18+ )
19+ if result .returncode == 0 :
20+ # Successfully queried a jj repo; jj only tracks non-ignored files
21+ # so no extra filtering is needed.
22+ return bool (result .stdout .strip ())
23+ # jj is installed but this is not a jj repository; fall back to git.
24+ except FileNotFoundError :
25+ pass # jj is not installed
26+
27+ # Fall back to git, ignoring untracked files.
28+ try :
29+ result = subprocess .run (
30+ ["git" , "status" , "--porcelain" , "--untracked-files=no" ],
31+ capture_output = True ,
32+ text = True ,
33+ )
34+ if result .returncode == 0 :
35+ return bool (result .stdout .strip ())
36+ except FileNotFoundError :
37+ pass # git is not installed
38+
39+ return False
40+
41+
942API_ENDPOINTS = {
1043 "dev" : "https://remote-settings-dev.allizom.org/v1/" ,
1144 "stage" : "https://remote-settings.allizom.org/v1/" ,
3770 parser .print_help ()
3871 sys .exit (1 )
3972
73+ if has_uncommitted_changes ():
74+ reply = input (
75+ "\n \n WARNING: There are local uncommitted changes. Are you sure you wish to proceed? (y/N):"
76+ ).lower ().strip ()
77+ if not reply or reply [0 ] != "y" :
78+ sys .exit (1 )
79+
4080# workspace = 'main' if args.server == 'dev' else 'main-workspace'
4181
4282API_ENDPOINT = API_ENDPOINTS [args .server ] + "buckets/%s/collections/%s/records" % (
5797
5898existingRecords = response .json ()
5999
60- # Handle python 2 backwards compatibility.
61- if sys .version_info [0 ] < 3 :
62- inputFn = raw_input
63- else :
64- inputFn = input
65-
66100
67101def getIdForRecord (record ):
68102 if args .collection == "search-config" :
@@ -88,7 +122,7 @@ def findRecord(id, recordSet):
88122
89123def yes_or_no (question ):
90124 while "the answer is invalid" :
91- reply = str (inputFn (question + " (y/n): " )).lower ().strip ()
125+ reply = str (input (question + " (y/n): " )).lower ().strip ()
92126 if reply [0 ] == "y" :
93127 return True
94128 if reply [0 ] == "n" :
@@ -145,7 +179,7 @@ def strip_record(record):
145179 recordsToRemove .append (record )
146180
147181if len (recordsToRemove ) > 0 :
148- print ("\Records to Remove:\n " )
182+ print ("\n Records to Remove:\n " )
149183
150184 for record in recordsToRemove :
151185 print (getIdForRecord (record ))
0 commit comments