gitpush-tool 0.2.6__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.6
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,36 +1,65 @@
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
- try:
16
- subprocess.run(["gh", "--version"], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
11
+ """Check if GitHub CLI is installed, attempt installation if not"""
12
+ if shutil.which("gh"):
17
13
  return True
18
- except FileNotFoundError:
19
- if platform.system() == "Windows":
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 platform.system() == "Darwin":
22
- return subprocess.run(["brew", "install", "gh"], check=True)
23
- elif platform.system() == "Linux":
24
- return subprocess.run(["sudo", "apt", "install", "-y", "gh"], check=True)
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 platform")
26
+ print("❌ Unsupported OS.")
27
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
28
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
54
+ return True
55
+ except Exception as e:
56
+ print(f"❌ Direct installation failed: {e}")
57
+ return False
29
58
 
30
59
  def gh_authenticated():
31
60
  """Check if user is authenticated with GitHub CLI"""
32
61
  try:
33
- result = subprocess.run(["gh", "auth", "status"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
62
+ result = subprocess.run(["gh", "auth", "status"], capture_output=True, text=True)
34
63
  return result.returncode == 0
35
64
  except:
36
65
  return False
@@ -47,22 +76,20 @@ def authenticate_with_gh():
47
76
  except subprocess.CalledProcessError:
48
77
  print("❌ Authentication failed")
49
78
  return False
50
- except FileNotFoundError:
51
- print("❌ GitHub CLI not found")
52
- return False
53
79
 
54
80
  def initialize_git_repository():
55
81
  """Initialize git repository if not already initialized"""
56
- if not os.path.exists(".git"):
57
- print("🛠 Initializing git repository")
58
- try:
59
- subprocess.run(["git", "init"], check=True)
60
- subprocess.run(["git", "branch", "-M", "main"], check=True)
61
-
62
- # Create basic .gitignore if doesn't exist
63
- if not os.path.exists(".gitignore"):
64
- with open(".gitignore", "w") as f:
65
- 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
66
93
  __pycache__/
67
94
  *.py[cod]
68
95
  *.so
@@ -86,21 +113,17 @@ Thumbs.db
86
113
  *.tmp
87
114
  *.bak
88
115
  """)
89
- print("📁 Created .gitignore file")
90
- return True
91
- except subprocess.CalledProcessError as e:
92
- print(f"❌ Failed to initialize Git repository: {e}")
93
- return False
94
- 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
95
121
 
96
122
  def create_initial_commit(commit_message="Initial commit"):
97
123
  """Create initial commit if no commits exist"""
98
124
  try:
99
- # Check if there are any commits
100
125
  result = subprocess.run(["git", "rev-list", "--count", "HEAD"],
101
- stdout=subprocess.PIPE,
102
- stderr=subprocess.PIPE,
103
- text=True)
126
+ capture_output=True, text=True)
104
127
  commit_count = int(result.stdout.strip()) if result.stdout.strip().isdigit() else 0
105
128
 
106
129
  if commit_count == 0:
@@ -116,42 +139,30 @@ def create_initial_commit(commit_message="Initial commit"):
116
139
  def create_with_gh_cli(repo_name, private=False, description="", commit_message="Initial commit"):
117
140
  """Create and push to new repository using GitHub CLI"""
118
141
  try:
119
- # First ensure we have a Git repository
120
- if not os.path.exists(".git"):
121
- if not initialize_git_repository():
122
- return False
142
+ if not os.path.exists(".git") and not initialize_git_repository():
143
+ return False
123
144
 
124
- # Create initial commit if needed
125
145
  if not create_initial_commit(commit_message):
126
146
  print("ℹ️ Using existing commits")
127
147
 
128
148
  private_flag = "--private" if private else "--public"
129
- cmd = [
130
- "gh", "repo", "create", repo_name,
131
- private_flag,
132
- "--source=.",
133
- "--remote=origin",
134
- "--push"
135
- ]
149
+ cmd = ["gh", "repo", "create", repo_name, private_flag,
150
+ "--source=.", "--remote=origin", "--push"]
136
151
 
137
152
  if description:
138
153
  cmd.extend(["--description", description])
139
154
 
140
155
  print("🚀 Creating repository and pushing code...")
141
- 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
142
165
 
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
166
  except subprocess.CalledProcessError as e:
156
167
  print(f"❌ Failed to create repository: {e.stderr if e.stderr else 'Unknown error'}")
157
168
  return False
@@ -162,17 +173,14 @@ def create_with_gh_cli(repo_name, private=False, description="", commit_message=
162
173
  def standard_git_push(commit_message, branch, remote, force=False, tags=False):
163
174
  """Handle standard git push operations"""
164
175
  try:
165
- # Stage all changes
166
176
  subprocess.run(["git", "add", "."], check=True)
167
177
 
168
- # Commit if message provided
169
178
  if commit_message:
170
179
  print(f"📦 Committing: '{commit_message}'")
171
180
  subprocess.run(["git", "commit", "-m", commit_message], check=True)
172
181
  else:
173
182
  print("ℹ️ No commit message provided - skipping commit")
174
183
 
175
- # Build push command
176
184
  push_cmd = ["git", "push"]
177
185
  if force:
178
186
  push_cmd.append("--force-with-lease")
@@ -189,42 +197,6 @@ def standard_git_push(commit_message, branch, remote, force=False, tags=False):
189
197
  print(f"❌ Push failed: {e}")
190
198
  return False
191
199
 
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
200
  def run():
229
201
  parser = argparse.ArgumentParser(
230
202
  description="🚀 Supercharged Git push tool with GitHub repo creation",
@@ -259,23 +231,20 @@ def run():
259
231
  print(" Linux: See https://github.com/cli/cli#installation")
260
232
  sys.exit(1)
261
233
 
262
- if not gh_authenticated():
263
- if not authenticate_with_gh():
264
- sys.exit(1)
234
+ if not gh_authenticated() and not authenticate_with_gh():
235
+ sys.exit(1)
265
236
 
266
- commit_msg = args.commit if args.commit else "Initial commit"
267
237
  if not create_with_gh_cli(
268
238
  args.new_repo,
269
239
  private=args.private,
270
240
  description=args.description or "",
271
- commit_message=commit_msg
241
+ commit_message=args.commit or "Initial commit"
272
242
  ):
273
243
  sys.exit(1)
274
244
  elif args.init:
275
245
  if initialize_git_repository():
276
246
  create_initial_commit(args.commit or "Initial commit")
277
247
  else:
278
- # Standard git push operation
279
248
  if not standard_git_push(
280
249
  args.commit,
281
250
  args.branch,
@@ -284,10 +253,6 @@ def run():
284
253
  args.tags
285
254
  ):
286
255
  sys.exit(1)
287
-
288
-
289
-
290
-
291
256
 
292
257
  if __name__ == "__main__":
293
258
  run()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gitpush-tool
3
- Version: 0.2.6
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.6",
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.6"
File without changes
File without changes
File without changes
File without changes