gitpush-tool 0.3.3__tar.gz → 0.3.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gitpush-tool
3
- Version: 0.3.3
3
+ Version: 0.3.5
4
4
  Summary: Supercharged Git push tool with automatic GitHub repo creation and pushing
5
5
  Home-page: https://github.com/inevitablegs/gitpush
6
6
  Author: Ganesh Sonawane
@@ -0,0 +1 @@
1
+ __version__ = "0.3.5"
@@ -461,22 +461,37 @@ def standard_git_push(commit_message, branch, remote, force=False, tags=False):
461
461
  if force:
462
462
  push_cmd.append("--force-with-lease")
463
463
  print("⚠️ Using safe force push (--force-with-lease).")
464
- if tags: push_cmd.append("--tags")
465
- if remote and branch: push_cmd.extend([remote, branch])
464
+ if tags:
465
+ push_cmd.append("--tags")
466
+ if remote and branch:
467
+ push_cmd.extend([remote, branch])
466
468
 
467
469
  print(f"🚀 Executing: {' '.join(push_cmd)}")
468
470
  subprocess.run(push_cmd, check=True)
469
471
  print("✅ Successfully pushed changes.")
470
472
  return True
473
+
471
474
  except subprocess.CalledProcessError as e:
472
475
  error_output = e.stderr.decode(errors='ignore').strip() if e.stderr else str(e)
476
+
473
477
  if "nothing to commit" in error_output:
474
478
  print("ℹ️ No changes to commit. Nothing to do.")
475
479
  return True
480
+
481
+ if "non-fast-forward" in error_output.lower():
482
+ print("\n❗ Detected non-fast-forward issue. Attempting rebase...")
483
+ if attempt_rebase(remote, branch):
484
+ print("🔁 Retrying push after rebase...")
485
+ return standard_git_push(commit_message, branch, remote, force, tags)
486
+ else:
487
+ print("❌ Rebase failed. Please resolve conflicts manually and re-run the push.")
488
+ return False
489
+
476
490
  print(f"❌ Push failed: {error_output}", file=sys.stderr)
477
491
  return False
478
492
 
479
493
 
494
+
480
495
  def has_incoming_changes(remote: str = "origin", branch: str = "main") -> bool:
481
496
  try:
482
497
  subprocess.run(["git", "fetch", remote], check=True, capture_output=True)
@@ -539,8 +554,42 @@ def show_merge_conflict_details():
539
554
  print(f"❌ Could not retrieve conflicted files: {str(e)}")
540
555
 
541
556
 
557
+ def attempt_rebase(remote: str, branch: str) -> bool:
558
+ print("🔁 Attempting: git pull --rebase")
559
+ try:
560
+ subprocess.run(["git", "pull", "--rebase", remote, branch], check=True)
561
+ print("✅ Rebase completed successfully.")
562
+ return True
563
+ except subprocess.CalledProcessError as e:
564
+ print(f"❌ Rebase failed: {e.stderr.decode(errors='ignore') if e.stderr else str(e)}")
565
+ show_merge_conflict_details()
566
+ return False
542
567
 
543
568
 
569
+ def get_git_sync_status(remote: str = "origin", branch: str = "main") -> tuple[str, int, int]:
570
+ """
571
+ Returns a tuple (status, behind, ahead) where status is one of:
572
+ 'ahead', 'behind', 'diverged', 'synced'
573
+ """
574
+ try:
575
+ subprocess.run(["git", "fetch", remote], check=True, capture_output=True)
576
+ result = subprocess.run(
577
+ ["git", "rev-list", "--left-right", "--count", f"{remote}/{branch}...{branch}"],
578
+ capture_output=True, text=True, check=True
579
+ )
580
+ behind_str, ahead_str = result.stdout.strip().split()
581
+ behind, ahead = int(behind_str), int(ahead_str)
582
+
583
+ if behind > 0 and ahead > 0:
584
+ return "diverged", behind, ahead
585
+ elif ahead > 0:
586
+ return "ahead", behind, ahead
587
+ elif behind > 0:
588
+ return "behind", behind, ahead
589
+ else:
590
+ return "synced", behind, ahead
591
+ except subprocess.CalledProcessError:
592
+ return "unknown", 0, 0
544
593
 
545
594
 
546
595
  # --- Main Entry Point ---
@@ -599,13 +648,26 @@ def run():
599
648
  print("✅ Git repository initialized successfully.")
600
649
 
601
650
  else:
602
- if has_incoming_changes(args.remote, target_branch):
603
- conflicts = pull_and_check_conflicts(args.remote, target_branch)
604
- if conflicts:
651
+ sync_status, behind, ahead = get_git_sync_status(args.remote, target_branch)
652
+ print(f"\n📊 Git status: {sync_status.upper()} (Behind: {behind}, Ahead: {ahead})")
653
+
654
+ if sync_status == "behind":
655
+ print("🔄 Your branch is behind remote. Pulling latest changes...")
656
+ if pull_and_check_conflicts(args.remote, target_branch):
605
657
  show_merge_conflict_details()
606
658
  print("\n❌ Resolve conflicts before pushing.")
607
659
  sys.exit(1)
608
660
 
661
+ elif sync_status == "diverged":
662
+ print("⚠️ Your branch has diverged from remote. Rebase recommended.")
663
+ if attempt_rebase(args.remote, target_branch):
664
+ print("✅ Rebase done. Proceeding to push...")
665
+ else:
666
+ print("❌ Rebase failed. Please resolve manually.")
667
+ sys.exit(1)
668
+
669
+
670
+
609
671
  if not standard_git_push(
610
672
  args.commit,
611
673
  target_branch,
@@ -616,4 +678,5 @@ def run():
616
678
  sys.exit(1)
617
679
 
618
680
  if __name__ == "__main__":
619
- run()
681
+ run()
682
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gitpush-tool
3
- Version: 0.3.3
3
+ Version: 0.3.5
4
4
  Summary: Supercharged Git push tool with automatic GitHub repo creation and pushing
5
5
  Home-page: https://github.com/inevitablegs/gitpush
6
6
  Author: Ganesh Sonawane
@@ -6,7 +6,7 @@ long_description = (Path(__file__).parent / "LONG_DESCRIPTION.md").read_text(enc
6
6
 
7
7
  setup(
8
8
  name="gitpush-tool",
9
- version="0.3.3",
9
+ version="0.3.5",
10
10
  packages=find_packages(),
11
11
  install_requires=[],
12
12
  entry_points={
@@ -1 +0,0 @@
1
- __version__ = "0.3.3"
File without changes
File without changes
File without changes
File without changes