gitpush-tool 0.2.5__tar.gz → 0.2.7__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.2.5
3
+ Version: 0.2.7
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.2.7"
@@ -1,22 +1,65 @@
1
- #!/usr/bin/env python3
2
1
  import os
3
2
  import argparse
4
3
  import sys
5
4
  import subprocess
6
- from datetime import datetime
5
+ import platform
6
+ import urllib.request
7
+ import tempfile
8
+ import shutil
7
9
 
8
10
  def check_gh_installed():
9
- """Check if GitHub CLI is installed"""
11
+ """Check if GitHub CLI is installed, attempt installation if not"""
12
+ if shutil.which("gh"):
13
+ return True
14
+
15
+ print("📦 GitHub CLI not found. Attempting installation...")
16
+ system = platform.system()
17
+
10
18
  try:
11
- subprocess.run(["gh", "--version"], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
19
+ if system == "Windows":
20
+ return install_gh_cli_windows()
21
+ elif system == "Darwin":
22
+ subprocess.run(["brew", "install", "gh"], check=True)
23
+ elif system == "Linux":
24
+ subprocess.run(["sudo", "apt", "install", "-y", "gh"], check=True)
25
+ else:
26
+ print("❌ Unsupported OS.")
27
+ return False
28
+
29
+ return shutil.which("gh") is not None
30
+ except Exception as e:
31
+ print(f"❌ Failed to install GitHub CLI: {e}")
32
+ return False
33
+
34
+ def install_gh_cli_windows():
35
+ """Install GitHub CLI on Windows using winget or direct download"""
36
+ # Try winget first
37
+ if shutil.which("winget"):
38
+ try:
39
+ subprocess.run(["winget", "install", "--id", "GitHub.cli", "--silent"], check=True)
40
+ return True
41
+ except subprocess.CalledProcessError:
42
+ print("⚠️ winget installation failed.")
43
+
44
+ # Fallback to direct download
45
+ try:
46
+ print("⬇️ Downloading GitHub CLI installer...")
47
+ url = "https://github.com/cli/cli/releases/latest/download/gh_2.46.0_windows_amd64.msi"
48
+ msi_path = os.path.join(tempfile.gettempdir(), "gh_installer.msi")
49
+ urllib.request.urlretrieve(url, msi_path)
50
+
51
+ print("🛠 Installing GitHub CLI...")
52
+ subprocess.run(["msiexec", "/i", msi_path, "/quiet", "/norestart"], check=True)
53
+ os.remove(msi_path) # Clean up
12
54
  return True
13
- except:
55
+ except Exception as e:
56
+ print(f"❌ Direct installation failed: {e}")
14
57
  return False
15
58
 
16
59
  def gh_authenticated():
17
60
  """Check if user is authenticated with GitHub CLI"""
18
61
  try:
19
- result = subprocess.run(["gh", "auth", "status"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
62
+ result = subprocess.run(["gh", "auth", "status"], capture_output=True, text=True)
20
63
  return result.returncode == 0
21
64
  except:
22
65
  return False
@@ -33,22 +76,20 @@ def authenticate_with_gh():
33
76
  except subprocess.CalledProcessError:
34
77
  print("❌ Authentication failed")
35
78
  return False
36
- except FileNotFoundError:
37
- print("❌ GitHub CLI not found")
38
- return False
39
79
 
40
80
  def initialize_git_repository():
41
81
  """Initialize git repository if not already initialized"""
42
- if not os.path.exists(".git"):
43
- print("🛠 Initializing git repository")
44
- try:
45
- subprocess.run(["git", "init"], check=True)
46
- subprocess.run(["git", "branch", "-M", "main"], check=True)
47
-
48
- # Create basic .gitignore if doesn't exist
49
- if not os.path.exists(".gitignore"):
50
- with open(".gitignore", "w") as f:
51
- f.write("""# Python
82
+ if os.path.exists(".git"):
83
+ return False
84
+
85
+ print("🛠 Initializing git repository")
86
+ try:
87
+ subprocess.run(["git", "init"], check=True)
88
+ subprocess.run(["git", "branch", "-M", "main"], check=True)
89
+
90
+ if not os.path.exists(".gitignore"):
91
+ with open(".gitignore", "w") as f:
92
+ f.write("""# Python
52
93
  __pycache__/
53
94
  *.py[cod]
54
95
  *.so
@@ -72,21 +113,17 @@ Thumbs.db
72
113
  *.tmp
73
114
  *.bak
74
115
  """)
75
- print("📁 Created .gitignore file")
76
- return True
77
- except subprocess.CalledProcessError as e:
78
- print(f"❌ Failed to initialize Git repository: {e}")
79
- return False
80
- return False
116
+ print("📁 Created .gitignore file")
117
+ return True
118
+ except subprocess.CalledProcessError as e:
119
+ print(f"❌ Failed to initialize Git repository: {e}")
120
+ return False
81
121
 
82
122
  def create_initial_commit(commit_message="Initial commit"):
83
123
  """Create initial commit if no commits exist"""
84
124
  try:
85
- # Check if there are any commits
86
125
  result = subprocess.run(["git", "rev-list", "--count", "HEAD"],
87
- stdout=subprocess.PIPE,
88
- stderr=subprocess.PIPE,
89
- text=True)
126
+ capture_output=True, text=True)
90
127
  commit_count = int(result.stdout.strip()) if result.stdout.strip().isdigit() else 0
91
128
 
92
129
  if commit_count == 0:
@@ -102,42 +139,30 @@ def create_initial_commit(commit_message="Initial commit"):
102
139
  def create_with_gh_cli(repo_name, private=False, description="", commit_message="Initial commit"):
103
140
  """Create and push to new repository using GitHub CLI"""
104
141
  try:
105
- # First ensure we have a Git repository
106
- if not os.path.exists(".git"):
107
- if not initialize_git_repository():
108
- return False
142
+ if not os.path.exists(".git") and not initialize_git_repository():
143
+ return False
109
144
 
110
- # Create initial commit if needed
111
145
  if not create_initial_commit(commit_message):
112
146
  print("ℹ️ Using existing commits")
113
147
 
114
148
  private_flag = "--private" if private else "--public"
115
- cmd = [
116
- "gh", "repo", "create", repo_name,
117
- private_flag,
118
- "--source=.",
119
- "--remote=origin",
120
- "--push"
121
- ]
149
+ cmd = ["gh", "repo", "create", repo_name, private_flag,
150
+ "--source=.", "--remote=origin", "--push"]
122
151
 
123
152
  if description:
124
153
  cmd.extend(["--description", description])
125
154
 
126
155
  print("🚀 Creating repository and pushing code...")
127
- result = subprocess.run(cmd, check=True)
156
+ subprocess.run(cmd, check=True)
157
+
158
+ url_result = subprocess.run(
159
+ ["gh", "repo", "view", "--json", "url", "--jq", ".url"],
160
+ capture_output=True, text=True, check=True
161
+ )
162
+ repo_url = url_result.stdout.strip()
163
+ print(f"✅ Successfully created repository: {repo_url}")
164
+ return True
128
165
 
129
- if result.returncode == 0:
130
- # Get the repo URL
131
- url_result = subprocess.run(
132
- ["gh", "repo", "view", "--json", "url", "--jq", ".url"],
133
- stdout=subprocess.PIPE,
134
- text=True,
135
- check=True
136
- )
137
- repo_url = url_result.stdout.strip()
138
- print(f"✅ Successfully created repository: {repo_url}")
139
- return True
140
- return False
141
166
  except subprocess.CalledProcessError as e:
142
167
  print(f"❌ Failed to create repository: {e.stderr if e.stderr else 'Unknown error'}")
143
168
  return False
@@ -148,17 +173,14 @@ def create_with_gh_cli(repo_name, private=False, description="", commit_message=
148
173
  def standard_git_push(commit_message, branch, remote, force=False, tags=False):
149
174
  """Handle standard git push operations"""
150
175
  try:
151
- # Stage all changes
152
176
  subprocess.run(["git", "add", "."], check=True)
153
177
 
154
- # Commit if message provided
155
178
  if commit_message:
156
179
  print(f"📦 Committing: '{commit_message}'")
157
180
  subprocess.run(["git", "commit", "-m", commit_message], check=True)
158
181
  else:
159
182
  print("ℹ️ No commit message provided - skipping commit")
160
183
 
161
- # Build push command
162
184
  push_cmd = ["git", "push"]
163
185
  if force:
164
186
  push_cmd.append("--force-with-lease")
@@ -209,23 +231,20 @@ def run():
209
231
  print(" Linux: See https://github.com/cli/cli#installation")
210
232
  sys.exit(1)
211
233
 
212
- if not gh_authenticated():
213
- if not authenticate_with_gh():
214
- sys.exit(1)
234
+ if not gh_authenticated() and not authenticate_with_gh():
235
+ sys.exit(1)
215
236
 
216
- commit_msg = args.commit if args.commit else "Initial commit"
217
237
  if not create_with_gh_cli(
218
238
  args.new_repo,
219
239
  private=args.private,
220
240
  description=args.description or "",
221
- commit_message=commit_msg
241
+ commit_message=args.commit or "Initial commit"
222
242
  ):
223
243
  sys.exit(1)
224
244
  elif args.init:
225
245
  if initialize_git_repository():
226
246
  create_initial_commit(args.commit or "Initial commit")
227
247
  else:
228
- # Standard git push operation
229
248
  if not standard_git_push(
230
249
  args.commit,
231
250
  args.branch,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gitpush-tool
3
- Version: 0.2.5
3
+ Version: 0.2.7
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.2.5",
9
+ version="0.2.7",
10
10
  packages=find_packages(),
11
11
  install_requires=[],
12
12
  entry_points={
@@ -1 +0,0 @@
1
- __version__ = "0.2.5"
File without changes
File without changes
File without changes
File without changes