gitpush-tool 0.2.1__tar.gz → 0.2.2__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.1
3
+ Version: 0.2.2
4
4
  Summary: A CLI tool to simplify Git push operations with intelligent defaults and options.
5
5
  Home-page: https://github.com/inevitablegs/gitpush
6
6
  Author: Ganesh Sonawane
@@ -0,0 +1 @@
1
+ __version__ = "0.2.2"
@@ -38,50 +38,13 @@ def authenticate_with_gh():
38
38
  print("❌ GitHub CLI not found")
39
39
  return False
40
40
 
41
- def create_with_gh_cli(repo_name, private=False, description="", commit_message="Initial commit"):
42
- """Create and push to new repository using GitHub CLI"""
43
- try:
44
- private_flag = "--private" if private else "--public"
45
- cmd = [
46
- "gh", "repo", "create", repo_name,
47
- private_flag,
48
- "--source=.",
49
- "--remote=origin",
50
- "--push"
51
- ]
52
-
53
- if description:
54
- cmd.extend(["--description", description])
55
-
56
- # Run the command
57
- result = subprocess.run(cmd, check=True)
58
-
59
- if result.returncode == 0:
60
- # Get the repo URL
61
- url_result = subprocess.run(
62
- ["gh", "repo", "view", "--json", "url", "--jq", ".url"],
63
- stdout=subprocess.PIPE,
64
- text=True,
65
- check=True
66
- )
67
- repo_url = url_result.stdout.strip()
68
- print(f"✅ Successfully created repository: {repo_url}")
69
- return True
70
- return False
71
- except subprocess.CalledProcessError as e:
72
- print(f"❌ Failed to create repository: {e.stderr}")
73
- return False
74
-
75
- def initialize_repository(remote_url=None):
76
- """Initialize git repository with sensible defaults"""
41
+ def initialize_git_repository():
42
+ """Initialize git repository if not already initialized"""
77
43
  if not os.path.exists(".git"):
78
44
  print("🛠 Initializing git repository")
79
45
  subprocess.run(["git", "init"], check=True)
80
46
  subprocess.run(["git", "branch", "-M", "main"], check=True)
81
47
 
82
- if remote_url:
83
- subprocess.run(["git", "remote", "add", "origin", remote_url], check=True)
84
-
85
48
  # Create basic .gitignore if doesn't exist
86
49
  if not os.path.exists(".gitignore"):
87
50
  with open(".gitignore", "w") as f:
@@ -109,12 +72,74 @@ Thumbs.db
109
72
  *.tmp
110
73
  *.bak
111
74
  """)
112
- print("📁 Created .gitignore file")
75
+ print("📁 Created .gitignore file")
76
+ return True
77
+ return False
78
+
79
+ def create_initial_commit(commit_message="Initial commit"):
80
+ """Create initial commit if no commits exist"""
81
+ try:
82
+ # Check if there are any commits
83
+ result = subprocess.run(["git", "rev-list", "--count", "HEAD"],
84
+ stdout=subprocess.PIPE,
85
+ stderr=subprocess.PIPE,
86
+ text=True)
87
+ commit_count = int(result.stdout.strip()) if result.stdout.strip().isdigit() else 0
88
+
89
+ if commit_count == 0:
90
+ print("📦 Creating initial commit")
91
+ subprocess.run(["git", "add", "."], check=True)
92
+ subprocess.run(["git", "commit", "-m", commit_message], check=True)
93
+ return True
94
+ return False
95
+ except subprocess.CalledProcessError:
96
+ return False
97
+
98
+ def create_with_gh_cli(repo_name, private=False, description="", commit_message="Initial commit"):
99
+ """Create and push to new repository using GitHub CLI"""
100
+ try:
101
+ private_flag = "--private" if private else "--public"
102
+ cmd = [
103
+ "gh", "repo", "create", repo_name,
104
+ private_flag,
105
+ "--source=.",
106
+ "--remote=origin",
107
+ "--push"
108
+ ]
109
+
110
+ if description:
111
+ cmd.extend(["--description", description])
112
+
113
+ # Initialize Git and create initial commit if needed
114
+ needs_init = initialize_git_repository()
115
+ needs_commit = create_initial_commit(commit_message)
116
+
117
+ if needs_init or needs_commit:
118
+ print("⚡ Set up local Git repository with initial commit")
119
+
120
+ # Run the create command
121
+ result = subprocess.run(cmd, check=True)
122
+
123
+ if result.returncode == 0:
124
+ # Get the repo URL
125
+ url_result = subprocess.run(
126
+ ["gh", "repo", "view", "--json", "url", "--jq", ".url"],
127
+ stdout=subprocess.PIPE,
128
+ text=True,
129
+ check=True
130
+ )
131
+ repo_url = url_result.stdout.strip()
132
+ print(f"✅ Successfully created repository: {repo_url}")
133
+ return True
134
+ return False
135
+ except subprocess.CalledProcessError as e:
136
+ print(f"❌ Failed to create repository: {e.stderr if e.stderr else 'Unknown error'}")
137
+ return False
113
138
 
114
139
  def check_for_updates():
115
140
  """Check for newer versions on PyPI"""
116
141
  try:
117
- current_version = "0.2.1" # Should match your setup.py
142
+ current_version = "0.2.2"
118
143
  response = requests.get("https://pypi.org/pypi/gitpush-tool/json", timeout=2)
119
144
  latest_version = response.json()["info"]["version"]
120
145
  if latest_version != current_version:
@@ -164,30 +189,35 @@ def run():
164
189
  if not authenticate_with_gh():
165
190
  sys.exit(1)
166
191
 
167
- # Create repository
192
+ # Create repository with automatic initialization
193
+ commit_msg = args.commit if args.commit else "Initial commit"
168
194
  if not create_with_gh_cli(
169
195
  args.new_repo,
170
196
  private=args.private,
171
197
  description=args.description or "",
172
- commit_message=args.commit or "Initial commit"
198
+ commit_message=commit_msg
173
199
  ):
174
200
  sys.exit(1)
201
+
202
+ # Exit after creating new repo unless there are other operations
203
+ if not args.commit and not args.force and not args.tags:
204
+ sys.exit(0)
175
205
 
176
206
  if args.init:
177
- initialize_repository()
207
+ if initialize_git_repository():
208
+ create_initial_commit(args.commit or "Initial commit")
178
209
 
179
- # Stage all changes
180
- subprocess.run(["git", "add", "."], check=True)
210
+ # Stage all changes if not in a new repo creation
211
+ if not args.new_repo:
212
+ subprocess.run(["git", "add", "."], check=True)
181
213
 
182
214
  if args.commit:
183
215
  print(f"📦 Committing: '{args.commit}'")
184
216
  try:
185
217
  subprocess.run(['git', 'commit', '-m', args.commit], check=True)
186
218
  except subprocess.CalledProcessError:
187
- print("❌ Commit failed")
219
+ print("❌ Commit failed - no changes to commit?")
188
220
  sys.exit(1)
189
- else:
190
- print("⚠️ Skipping commit (no message provided)")
191
221
 
192
222
  # Build push command
193
223
  push_cmd = ["git", "push"]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gitpush-tool
3
- Version: 0.2.1
3
+ Version: 0.2.2
4
4
  Summary: A CLI tool to simplify Git push operations with intelligent defaults and options.
5
5
  Home-page: https://github.com/inevitablegs/gitpush
6
6
  Author: Ganesh Sonawane
@@ -3,7 +3,7 @@ from pathlib import Path
3
3
 
4
4
  setup(
5
5
  name="gitpush-tool",
6
- version="0.2.1",
6
+ version="0.2.2",
7
7
  packages=find_packages(),
8
8
  install_requires=[
9
9
  'requests>=2.25.0',
@@ -1 +0,0 @@
1
- __version__ = "0.2.1"
File without changes
File without changes
File without changes
File without changes