Skip to content

Commit a723b1c

Browse files
committed
more tweaks
1 parent 4e9c692 commit a723b1c

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

gitpull.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,16 @@ def main():
281281
print("Failed: UPSTREAM_REPO_DIR environment variable is not set.")
282282
sys.exit(1)
283283

284+
# Get the source repository
285+
origin = f"{UPSTREAM_REPO_DIR}/{args.ebook_number}.git"
286+
# Check if the source repository exists by trying to get its remote URL
287+
try:
288+
run_command(["git", "ls-remote", origin], noerror=True)
289+
except subprocess.CalledProcessError:
290+
logger.error(f"Source repository {origin} does not exist or is not accessible")
291+
print(f"Failed: source repository {origin} does not exist or is not accessible.")
292+
sys.exit(1)
293+
284294
# Check if target exists and is a directory
285295
target_path = Path(args.target_path).resolve()
286296
if not target_path.exists() or not target_path.is_dir():
@@ -298,14 +308,16 @@ def main():
298308
print(f"Failed: {args.target_path} does not exist or is not a directory")
299309
sys.exit(1)
300310

301-
# Update the directory
302-
origin = f"{UPSTREAM_REPO_DIR}/{args.ebook_number}.git/"
303-
304-
# destination is a directory named with the ebook number under the target path
305-
destination = f"{args.target_path}/{args.ebook_number}"
311+
# Destination is a directory named with the ebook number under the target path
312+
destination = Path(args.target_path).expanduser().resolve() / str(args.ebook_number)
306313
logger.info(f"Pulling from {origin} to {destination}")
307314

308-
success = update_folder(origin, destination)
315+
try:
316+
success = update_folder(origin, destination)
317+
except subprocess.CalledProcessError as e:
318+
logger.error(f"Unexpected git operation failure: {e}")
319+
success = False
320+
309321
# Remove Git history if not needed, but only if the update was successful to avoid
310322
# deleting existing files on failure
311323
if args.norepo and success:

0 commit comments

Comments
 (0)