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.
- {gitpush_tool-0.2.5/gitpush_tool.egg-info → gitpush_tool-0.2.7}/PKG-INFO +1 -1
- gitpush_tool-0.2.7/gitpush_tool/__init__.py +1 -0
- {gitpush_tool-0.2.5 → gitpush_tool-0.2.7}/gitpush_tool/cli.py +82 -63
- {gitpush_tool-0.2.5 → gitpush_tool-0.2.7/gitpush_tool.egg-info}/PKG-INFO +1 -1
- {gitpush_tool-0.2.5 → gitpush_tool-0.2.7}/setup.py +1 -1
- gitpush_tool-0.2.5/gitpush_tool/__init__.py +0 -1
- {gitpush_tool-0.2.5 → gitpush_tool-0.2.7}/LICENSE +0 -0
- {gitpush_tool-0.2.5 → gitpush_tool-0.2.7}/MANIFEST.in +0 -0
- {gitpush_tool-0.2.5 → gitpush_tool-0.2.7}/README.md +0 -0
- {gitpush_tool-0.2.5 → gitpush_tool-0.2.7}/gitpush_tool/__doc__.py +0 -0
- {gitpush_tool-0.2.5 → gitpush_tool-0.2.7}/gitpush_tool.egg-info/SOURCES.txt +0 -0
- {gitpush_tool-0.2.5 → gitpush_tool-0.2.7}/gitpush_tool.egg-info/dependency_links.txt +0 -0
- {gitpush_tool-0.2.5 → gitpush_tool-0.2.7}/gitpush_tool.egg-info/entry_points.txt +0 -0
- {gitpush_tool-0.2.5 → gitpush_tool-0.2.7}/gitpush_tool.egg-info/top_level.txt +0 -0
- {gitpush_tool-0.2.5 → gitpush_tool-0.2.7}/pyproject.toml +0 -0
- {gitpush_tool-0.2.5 → gitpush_tool-0.2.7}/setup.cfg +0 -0
|
@@ -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
|
-
|
|
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
|
-
|
|
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"],
|
|
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
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
-
|
|
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
|
-
|
|
106
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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=
|
|
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 +0,0 @@
|
|
|
1
|
-
__version__ = "0.2.5"
|
|
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
|