gitpush-tool 0.2.6__tar.gz → 0.2.8__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.
- {gitpush_tool-0.2.6/gitpush_tool.egg-info → gitpush_tool-0.2.8}/PKG-INFO +1 -1
- gitpush_tool-0.2.8/gitpush_tool/__init__.py +1 -0
- {gitpush_tool-0.2.6 → gitpush_tool-0.2.8}/gitpush_tool/cli.py +105 -111
- {gitpush_tool-0.2.6 → gitpush_tool-0.2.8/gitpush_tool.egg-info}/PKG-INFO +1 -1
- {gitpush_tool-0.2.6 → gitpush_tool-0.2.8}/setup.py +1 -1
- gitpush_tool-0.2.6/gitpush_tool/__init__.py +0 -1
- {gitpush_tool-0.2.6 → gitpush_tool-0.2.8}/LICENSE +0 -0
- {gitpush_tool-0.2.6 → gitpush_tool-0.2.8}/MANIFEST.in +0 -0
- {gitpush_tool-0.2.6 → gitpush_tool-0.2.8}/README.md +0 -0
- {gitpush_tool-0.2.6 → gitpush_tool-0.2.8}/gitpush_tool/__doc__.py +0 -0
- {gitpush_tool-0.2.6 → gitpush_tool-0.2.8}/gitpush_tool.egg-info/SOURCES.txt +0 -0
- {gitpush_tool-0.2.6 → gitpush_tool-0.2.8}/gitpush_tool.egg-info/dependency_links.txt +0 -0
- {gitpush_tool-0.2.6 → gitpush_tool-0.2.8}/gitpush_tool.egg-info/entry_points.txt +0 -0
- {gitpush_tool-0.2.6 → gitpush_tool-0.2.8}/gitpush_tool.egg-info/top_level.txt +0 -0
- {gitpush_tool-0.2.6 → gitpush_tool-0.2.8}/pyproject.toml +0 -0
- {gitpush_tool-0.2.6 → gitpush_tool-0.2.8}/setup.cfg +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.2.8"
|
|
@@ -1,36 +1,94 @@
|
|
|
1
|
-
|
|
2
1
|
import os
|
|
3
2
|
import argparse
|
|
4
3
|
import sys
|
|
5
4
|
import subprocess
|
|
6
|
-
from datetime import datetime
|
|
7
|
-
import os
|
|
8
|
-
import subprocess
|
|
9
5
|
import platform
|
|
10
6
|
import urllib.request
|
|
11
7
|
import tempfile
|
|
12
8
|
import shutil
|
|
13
9
|
|
|
14
10
|
def check_gh_installed():
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
"""Check if GitHub CLI is installed, attempt installation if not"""
|
|
12
|
+
if shutil.which("gh"):
|
|
17
13
|
return True
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
|
|
15
|
+
print("📦 GitHub CLI not found. Attempting installation...")
|
|
16
|
+
system = platform.system()
|
|
17
|
+
|
|
18
|
+
try:
|
|
19
|
+
if system == "Windows":
|
|
20
20
|
return install_gh_cli_windows()
|
|
21
|
-
elif
|
|
22
|
-
|
|
23
|
-
elif
|
|
24
|
-
|
|
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
25
|
else:
|
|
26
|
-
print("❌ Unsupported
|
|
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
|
+
import os
|
|
35
|
+
import subprocess
|
|
36
|
+
import shutil
|
|
37
|
+
import tempfile
|
|
38
|
+
import urllib.request
|
|
39
|
+
import json
|
|
40
|
+
|
|
41
|
+
def install_gh_cli_windows():
|
|
42
|
+
"""Install GitHub CLI on Windows using winget or direct download"""
|
|
43
|
+
# Try winget first
|
|
44
|
+
if shutil.which("winget"):
|
|
45
|
+
try:
|
|
46
|
+
print("📦 Attempting to install GitHub CLI with winget...")
|
|
47
|
+
subprocess.run(["winget", "install", "--id", "GitHub.cli", "--silent"], check=True)
|
|
48
|
+
print("✅ GitHub CLI installed successfully via winget.")
|
|
49
|
+
return True
|
|
50
|
+
except (subprocess.CalledProcessError, FileNotFoundError):
|
|
51
|
+
print("⚠️ Winget installation failed. Falling back to direct download.")
|
|
52
|
+
|
|
53
|
+
# Fallback to direct download
|
|
54
|
+
try:
|
|
55
|
+
print("⬇️ Finding the latest GitHub CLI release for Windows...")
|
|
56
|
+
api_url = "https://api.github.com/repos/cli/cli/releases/latest"
|
|
57
|
+
with urllib.request.urlopen(api_url) as response:
|
|
58
|
+
data = json.loads(response.read().decode())
|
|
59
|
+
|
|
60
|
+
# Find the correct MSI asset
|
|
61
|
+
msi_url = None
|
|
62
|
+
for asset in data.get("assets", []):
|
|
63
|
+
if asset.get("name", "").endswith("_windows_amd64.msi"):
|
|
64
|
+
msi_url = asset.get("browser_download_url")
|
|
65
|
+
break
|
|
66
|
+
|
|
67
|
+
if not msi_url:
|
|
68
|
+
print("❌ Could not find a downloadable MSI file for the latest release.")
|
|
27
69
|
return False
|
|
28
70
|
|
|
71
|
+
msi_path = os.path.join(tempfile.gettempdir(), "gh_installer.msi")
|
|
72
|
+
|
|
73
|
+
print(f"⬇️ Downloading GitHub CLI from: {msi_url}")
|
|
74
|
+
urllib.request.urlretrieve(msi_url, msi_path)
|
|
75
|
+
|
|
76
|
+
print("🛠️ Installing GitHub CLI...")
|
|
77
|
+
# Use msiexec for silent installation
|
|
78
|
+
subprocess.run(["msiexec", "/i", msi_path, "/quiet", "/norestart"], check=True)
|
|
79
|
+
|
|
80
|
+
# Clean up the downloaded file
|
|
81
|
+
os.remove(msi_path)
|
|
82
|
+
print("✅ GitHub CLI installed successfully.")
|
|
83
|
+
return True
|
|
84
|
+
except Exception as e:
|
|
85
|
+
print(f"❌ Direct installation failed: {e}")
|
|
86
|
+
return False
|
|
29
87
|
|
|
30
88
|
def gh_authenticated():
|
|
31
89
|
"""Check if user is authenticated with GitHub CLI"""
|
|
32
90
|
try:
|
|
33
|
-
result = subprocess.run(["gh", "auth", "status"],
|
|
91
|
+
result = subprocess.run(["gh", "auth", "status"], capture_output=True, text=True)
|
|
34
92
|
return result.returncode == 0
|
|
35
93
|
except:
|
|
36
94
|
return False
|
|
@@ -47,22 +105,20 @@ def authenticate_with_gh():
|
|
|
47
105
|
except subprocess.CalledProcessError:
|
|
48
106
|
print("❌ Authentication failed")
|
|
49
107
|
return False
|
|
50
|
-
except FileNotFoundError:
|
|
51
|
-
print("❌ GitHub CLI not found")
|
|
52
|
-
return False
|
|
53
108
|
|
|
54
109
|
def initialize_git_repository():
|
|
55
110
|
"""Initialize git repository if not already initialized"""
|
|
56
|
-
if
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
111
|
+
if os.path.exists(".git"):
|
|
112
|
+
return False
|
|
113
|
+
|
|
114
|
+
print("🛠 Initializing git repository")
|
|
115
|
+
try:
|
|
116
|
+
subprocess.run(["git", "init"], check=True)
|
|
117
|
+
subprocess.run(["git", "branch", "-M", "main"], check=True)
|
|
118
|
+
|
|
119
|
+
if not os.path.exists(".gitignore"):
|
|
120
|
+
with open(".gitignore", "w") as f:
|
|
121
|
+
f.write("""# Python
|
|
66
122
|
__pycache__/
|
|
67
123
|
*.py[cod]
|
|
68
124
|
*.so
|
|
@@ -86,21 +142,17 @@ Thumbs.db
|
|
|
86
142
|
*.tmp
|
|
87
143
|
*.bak
|
|
88
144
|
""")
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return False
|
|
145
|
+
print("📁 Created .gitignore file")
|
|
146
|
+
return True
|
|
147
|
+
except subprocess.CalledProcessError as e:
|
|
148
|
+
print(f"❌ Failed to initialize Git repository: {e}")
|
|
149
|
+
return False
|
|
95
150
|
|
|
96
151
|
def create_initial_commit(commit_message="Initial commit"):
|
|
97
152
|
"""Create initial commit if no commits exist"""
|
|
98
153
|
try:
|
|
99
|
-
# Check if there are any commits
|
|
100
154
|
result = subprocess.run(["git", "rev-list", "--count", "HEAD"],
|
|
101
|
-
|
|
102
|
-
stderr=subprocess.PIPE,
|
|
103
|
-
text=True)
|
|
155
|
+
capture_output=True, text=True)
|
|
104
156
|
commit_count = int(result.stdout.strip()) if result.stdout.strip().isdigit() else 0
|
|
105
157
|
|
|
106
158
|
if commit_count == 0:
|
|
@@ -116,42 +168,30 @@ def create_initial_commit(commit_message="Initial commit"):
|
|
|
116
168
|
def create_with_gh_cli(repo_name, private=False, description="", commit_message="Initial commit"):
|
|
117
169
|
"""Create and push to new repository using GitHub CLI"""
|
|
118
170
|
try:
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
if not initialize_git_repository():
|
|
122
|
-
return False
|
|
171
|
+
if not os.path.exists(".git") and not initialize_git_repository():
|
|
172
|
+
return False
|
|
123
173
|
|
|
124
|
-
# Create initial commit if needed
|
|
125
174
|
if not create_initial_commit(commit_message):
|
|
126
175
|
print("ℹ️ Using existing commits")
|
|
127
176
|
|
|
128
177
|
private_flag = "--private" if private else "--public"
|
|
129
|
-
cmd = [
|
|
130
|
-
|
|
131
|
-
private_flag,
|
|
132
|
-
"--source=.",
|
|
133
|
-
"--remote=origin",
|
|
134
|
-
"--push"
|
|
135
|
-
]
|
|
178
|
+
cmd = ["gh", "repo", "create", repo_name, private_flag,
|
|
179
|
+
"--source=.", "--remote=origin", "--push"]
|
|
136
180
|
|
|
137
181
|
if description:
|
|
138
182
|
cmd.extend(["--description", description])
|
|
139
183
|
|
|
140
184
|
print("🚀 Creating repository and pushing code...")
|
|
141
|
-
|
|
185
|
+
subprocess.run(cmd, check=True)
|
|
186
|
+
|
|
187
|
+
url_result = subprocess.run(
|
|
188
|
+
["gh", "repo", "view", "--json", "url", "--jq", ".url"],
|
|
189
|
+
capture_output=True, text=True, check=True
|
|
190
|
+
)
|
|
191
|
+
repo_url = url_result.stdout.strip()
|
|
192
|
+
print(f"✅ Successfully created repository: {repo_url}")
|
|
193
|
+
return True
|
|
142
194
|
|
|
143
|
-
if result.returncode == 0:
|
|
144
|
-
# Get the repo URL
|
|
145
|
-
url_result = subprocess.run(
|
|
146
|
-
["gh", "repo", "view", "--json", "url", "--jq", ".url"],
|
|
147
|
-
stdout=subprocess.PIPE,
|
|
148
|
-
text=True,
|
|
149
|
-
check=True
|
|
150
|
-
)
|
|
151
|
-
repo_url = url_result.stdout.strip()
|
|
152
|
-
print(f"✅ Successfully created repository: {repo_url}")
|
|
153
|
-
return True
|
|
154
|
-
return False
|
|
155
195
|
except subprocess.CalledProcessError as e:
|
|
156
196
|
print(f"❌ Failed to create repository: {e.stderr if e.stderr else 'Unknown error'}")
|
|
157
197
|
return False
|
|
@@ -162,17 +202,14 @@ def create_with_gh_cli(repo_name, private=False, description="", commit_message=
|
|
|
162
202
|
def standard_git_push(commit_message, branch, remote, force=False, tags=False):
|
|
163
203
|
"""Handle standard git push operations"""
|
|
164
204
|
try:
|
|
165
|
-
# Stage all changes
|
|
166
205
|
subprocess.run(["git", "add", "."], check=True)
|
|
167
206
|
|
|
168
|
-
# Commit if message provided
|
|
169
207
|
if commit_message:
|
|
170
208
|
print(f"📦 Committing: '{commit_message}'")
|
|
171
209
|
subprocess.run(["git", "commit", "-m", commit_message], check=True)
|
|
172
210
|
else:
|
|
173
211
|
print("ℹ️ No commit message provided - skipping commit")
|
|
174
212
|
|
|
175
|
-
# Build push command
|
|
176
213
|
push_cmd = ["git", "push"]
|
|
177
214
|
if force:
|
|
178
215
|
push_cmd.append("--force-with-lease")
|
|
@@ -189,42 +226,6 @@ def standard_git_push(commit_message, branch, remote, force=False, tags=False):
|
|
|
189
226
|
print(f"❌ Push failed: {e}")
|
|
190
227
|
return False
|
|
191
228
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
def install_gh_cli_windows():
|
|
196
|
-
"""Install GitHub CLI on Windows using winget or direct download"""
|
|
197
|
-
print("📦 GitHub CLI not found. Attempting installation on Windows...")
|
|
198
|
-
|
|
199
|
-
# First, try using winget
|
|
200
|
-
try:
|
|
201
|
-
subprocess.run(["winget", "--version"], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
202
|
-
print("👉 Installing via winget...")
|
|
203
|
-
subprocess.run(["winget", "install", "--id", "GitHub.cli", "-e", "--silent"], check=True)
|
|
204
|
-
print("✅ GitHub CLI installed successfully via winget.")
|
|
205
|
-
return True
|
|
206
|
-
except Exception as e:
|
|
207
|
-
print("⚠️ winget not available or failed. Trying direct download...")
|
|
208
|
-
|
|
209
|
-
# Fallback: Direct download from GitHub
|
|
210
|
-
try:
|
|
211
|
-
print("⬇️ Downloading GitHub CLI installer...")
|
|
212
|
-
url = "https://github.com/cli/cli/releases/latest/download/gh_2.46.0_windows_amd64.msi"
|
|
213
|
-
temp_dir = tempfile.mkdtemp()
|
|
214
|
-
msi_path = os.path.join(temp_dir, "gh.msi")
|
|
215
|
-
urllib.request.urlretrieve(url, msi_path)
|
|
216
|
-
|
|
217
|
-
print("🛠 Installing GitHub CLI...")
|
|
218
|
-
subprocess.run(["msiexec", "/i", msi_path, "/quiet", "/norestart"], check=True)
|
|
219
|
-
|
|
220
|
-
shutil.rmtree(temp_dir) # clean up
|
|
221
|
-
print("✅ GitHub CLI installed successfully via MSI.")
|
|
222
|
-
return True
|
|
223
|
-
except Exception as e:
|
|
224
|
-
print(f"❌ Direct installation failed: {e}")
|
|
225
|
-
return False
|
|
226
|
-
|
|
227
|
-
|
|
228
229
|
def run():
|
|
229
230
|
parser = argparse.ArgumentParser(
|
|
230
231
|
description="🚀 Supercharged Git push tool with GitHub repo creation",
|
|
@@ -259,23 +260,20 @@ def run():
|
|
|
259
260
|
print(" Linux: See https://github.com/cli/cli#installation")
|
|
260
261
|
sys.exit(1)
|
|
261
262
|
|
|
262
|
-
if not gh_authenticated():
|
|
263
|
-
|
|
264
|
-
sys.exit(1)
|
|
263
|
+
if not gh_authenticated() and not authenticate_with_gh():
|
|
264
|
+
sys.exit(1)
|
|
265
265
|
|
|
266
|
-
commit_msg = args.commit if args.commit else "Initial commit"
|
|
267
266
|
if not create_with_gh_cli(
|
|
268
267
|
args.new_repo,
|
|
269
268
|
private=args.private,
|
|
270
269
|
description=args.description or "",
|
|
271
|
-
commit_message=
|
|
270
|
+
commit_message=args.commit or "Initial commit"
|
|
272
271
|
):
|
|
273
272
|
sys.exit(1)
|
|
274
273
|
elif args.init:
|
|
275
274
|
if initialize_git_repository():
|
|
276
275
|
create_initial_commit(args.commit or "Initial commit")
|
|
277
276
|
else:
|
|
278
|
-
# Standard git push operation
|
|
279
277
|
if not standard_git_push(
|
|
280
278
|
args.commit,
|
|
281
279
|
args.branch,
|
|
@@ -284,10 +282,6 @@ def run():
|
|
|
284
282
|
args.tags
|
|
285
283
|
):
|
|
286
284
|
sys.exit(1)
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
285
|
|
|
292
286
|
if __name__ == "__main__":
|
|
293
287
|
run()
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.2.6"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|