lgit-cli 4.1.0__py3-none-any.whl → 4.2.0__py3-none-any.whl

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.
lgit/__init__.py CHANGED
@@ -8,7 +8,7 @@ from typing import TYPE_CHECKING, Any
8
8
  try:
9
9
  __version__ = metadata.version("lgit-cli")
10
10
  except metadata.PackageNotFoundError:
11
- __version__ = "4.1.0"
11
+ __version__ = "4.2.0"
12
12
 
13
13
  _CORE_MODEL_EXPORTS = (
14
14
  "Mode",
lgit/cli.py CHANGED
@@ -1029,24 +1029,37 @@ def _bash_completion(specs: list[dict[str, Any]]) -> str:
1029
1029
  def _zsh_completion(specs: list[dict[str, Any]]) -> str:
1030
1030
  lines = ["#compdef lgit", "", "_lgit() {", " _arguments -s -S \\"]
1031
1031
  for spec in specs:
1032
- lines.append(f" {_sh_single_quote(_zsh_option_spec(spec))} \\")
1032
+ lines.append(f" {_zsh_option_spec(spec)} \\")
1033
1033
  lines.append(" '*:context:_files'")
1034
1034
  lines.append("}")
1035
1035
  lines.append("")
1036
- lines.append('_lgit "$@"')
1036
+ # Work whether the file is autoloaded from $fpath (compsys calls `_lgit`) or
1037
+ # sourced directly from a startup file (register the completer via compdef).
1038
+ lines.append('if [ "$funcstack[1]" = "_lgit" ]; then')
1039
+ lines.append(' _lgit "$@"')
1040
+ lines.append("else")
1041
+ lines.append(" compdef _lgit lgit")
1042
+ lines.append("fi")
1037
1043
  return "\n".join(lines) + "\n"
1038
1044
 
1039
1045
 
1040
1046
  def _zsh_option_spec(spec: dict[str, Any]) -> str:
1047
+ # A brace alternation must stay unquoted so zsh expands `{-h,--help}` into one
1048
+ # `_arguments` spec per flag; quoting the whole token makes zsh treat the literal
1049
+ # `{-h,--help}[...]` as a single (invalid) argument. The body is quoted separately.
1041
1050
  options = spec["options"]
1042
- opt_expr = "{" + ",".join(options) + "}" if len(options) > 1 else options[0]
1051
+ opt_expr = "{" + ",".join(options) + "}" if len(options) > 1 else _sh_single_quote(options[0])
1052
+ return opt_expr + _sh_single_quote(_zsh_option_body(spec))
1053
+
1054
+
1055
+ def _zsh_option_body(spec: dict[str, Any]) -> str:
1043
1056
  desc = _zsh_escape(spec["help"])
1044
1057
  if spec["choices"]:
1045
1058
  values = " ".join(_zsh_escape(choice) for choice in spec["choices"])
1046
- return f"{opt_expr}[{desc}]:{spec['metavar']}:({values})"
1059
+ return f"[{desc}]:{spec['metavar']}:({values})"
1047
1060
  if spec["takes_value"]:
1048
- return f"{opt_expr}[{desc}]:{spec['metavar']}:_files"
1049
- return f"{opt_expr}[{desc}]"
1061
+ return f"[{desc}]:{spec['metavar']}:_files"
1062
+ return f"[{desc}]"
1050
1063
 
1051
1064
 
1052
1065
  def _fish_completion(specs: list[dict[str, Any]]) -> str:
lgit/errors.py CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
+ import shlex
5
6
  from dataclasses import dataclass
6
7
  from pathlib import Path
7
8
  from typing import Any
@@ -31,7 +32,11 @@ class GitIndexLocked(GitError):
31
32
  self.lock_path = lock_path
32
33
 
33
34
  def __str__(self) -> str:
34
- return f"{self.message}: {self.lock_path}"
35
+ quoted = shlex.quote(str(self.lock_path))
36
+ return (
37
+ f"{self.message}: {self.lock_path} — another git process may be running; "
38
+ f"if not, remove the stale lock with: rm {quoted}"
39
+ )
35
40
 
36
41
 
37
42
  @dataclass(slots=True)
lgit/git.py CHANGED
@@ -22,6 +22,12 @@ _GIT_BACKGROUND_CONFIG = (
22
22
 
23
23
  _DISABLE_GIT_BACKGROUND_FEATURES = True
24
24
 
25
+ # A concurrent git process (editor integration, fsmonitor, a parallel `git` call) often
26
+ # holds `index.lock` for a fraction of a second. Retrying briefly clears that transient
27
+ # contention without ever deleting a lock a live process may still own.
28
+ _INDEX_LOCK_RETRY_ATTEMPTS = 5
29
+ _INDEX_LOCK_RETRY_DELAY_S = 0.25
30
+
25
31
 
26
32
  def init_git_command_settings(config: object) -> None:
27
33
  """Initialize process-wide git subprocess settings from config."""
@@ -100,6 +106,11 @@ def git_command_env(
100
106
  if disable_background_features is None:
101
107
  disable_background_features = _DISABLE_GIT_BACKGROUND_FEATURES
102
108
  if disable_background_features:
109
+ # Read-only ops (status/diff/ls-files/...) opportunistically take `index.lock` to
110
+ # write back refreshed stat info. Suppress that so lgit never contends with the
111
+ # user's concurrent git while it sits in long LLM calls; mandatory locks for
112
+ # add/commit are unaffected.
113
+ env["GIT_OPTIONAL_LOCKS"] = "0"
103
114
  try:
104
115
  offset = int(env.get("GIT_CONFIG_COUNT", "0"))
105
116
  except ValueError:
@@ -164,6 +175,20 @@ def _raise_git_error(
164
175
  raise GitError(f"git {' '.join(os.fspath(arg) for arg in args)} failed: {detail}")
165
176
 
166
177
 
178
+ def _retry_index_lock(stderr: str, attempt: int) -> bool:
179
+ """Sleep and report whether a locked-index failure should be retried.
180
+
181
+ Returns ``True`` after a short backoff when ``stderr`` reports an `index.lock`
182
+ contention and retries remain; ``False`` otherwise (not a lock error, or the
183
+ bounded attempts are exhausted). Never removes the lock — a live git process may
184
+ still own it.
185
+ """
186
+ if "index.lock" not in stderr or attempt + 1 >= _INDEX_LOCK_RETRY_ATTEMPTS:
187
+ return False
188
+ time.sleep(_INDEX_LOCK_RETRY_DELAY_S)
189
+ return True
190
+
191
+
167
192
  def run_git(
168
193
  args: Sequence[str | os.PathLike[str]],
169
194
  *,
@@ -177,20 +202,23 @@ def run_git(
177
202
  ) -> GitResult:
178
203
  """Run git with explicit argv and return captured UTF-8 text output."""
179
204
 
180
- argv, completed = _run_git_process(
181
- args,
182
- cwd=cwd,
183
- input_data=input_text,
184
- text=True,
185
- env=env,
186
- index_file=index_file,
187
- disable_background_features=disable_background_features,
188
- )
189
- result = GitResult(argv, completed.returncode, completed.stdout, completed.stderr)
190
205
  allowed = set(allow_exit_codes)
191
- if check and completed.returncode != 0 and completed.returncode not in allowed:
192
- _raise_git_error(args, cwd, completed.stdout, completed.stderr)
193
- return result
206
+ for attempt in range(_INDEX_LOCK_RETRY_ATTEMPTS):
207
+ argv, completed = _run_git_process(
208
+ args,
209
+ cwd=cwd,
210
+ input_data=input_text,
211
+ text=True,
212
+ env=env,
213
+ index_file=index_file,
214
+ disable_background_features=disable_background_features,
215
+ )
216
+ if check and completed.returncode != 0 and completed.returncode not in allowed:
217
+ if _retry_index_lock(completed.stderr, attempt):
218
+ continue
219
+ _raise_git_error(args, cwd, completed.stdout, completed.stderr)
220
+ return GitResult(argv, completed.returncode, completed.stdout, completed.stderr)
221
+ raise AssertionError("unreachable: run_git retry loop exited without returning")
194
222
 
195
223
 
196
224
  def run_git_bytes(
@@ -206,22 +234,25 @@ def run_git_bytes(
206
234
  ) -> GitBytesResult:
207
235
  """Run git and preserve stdout as raw bytes."""
208
236
 
209
- argv, completed = _run_git_process(
210
- args,
211
- cwd=cwd,
212
- input_data=input_bytes,
213
- text=False,
214
- env=env,
215
- index_file=index_file,
216
- disable_background_features=disable_background_features,
217
- )
218
- result = GitBytesResult(argv, completed.returncode, completed.stdout, completed.stderr)
219
237
  allowed = set(allow_exit_codes)
220
- if check and completed.returncode != 0 and completed.returncode not in allowed:
221
- stderr = completed.stderr.decode("utf-8", errors="replace")
222
- stdout = completed.stdout.decode("utf-8", errors="replace")
223
- _raise_git_error(args, cwd, stdout, stderr)
224
- return result
238
+ for attempt in range(_INDEX_LOCK_RETRY_ATTEMPTS):
239
+ argv, completed = _run_git_process(
240
+ args,
241
+ cwd=cwd,
242
+ input_data=input_bytes,
243
+ text=False,
244
+ env=env,
245
+ index_file=index_file,
246
+ disable_background_features=disable_background_features,
247
+ )
248
+ if check and completed.returncode != 0 and completed.returncode not in allowed:
249
+ stderr = completed.stderr.decode("utf-8", errors="replace")
250
+ if _retry_index_lock(stderr, attempt):
251
+ continue
252
+ stdout = completed.stdout.decode("utf-8", errors="replace")
253
+ _raise_git_error(args, cwd, stdout, stderr)
254
+ return GitBytesResult(argv, completed.returncode, completed.stdout, completed.stderr)
255
+ raise AssertionError("unreachable: run_git_bytes retry loop exited without returning")
225
256
 
226
257
 
227
258
  class TempGitIndex:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lgit-cli
3
- Version: 4.1.0
3
+ Version: 4.2.0
4
4
  Summary: AI-powered git commit message generator using Claude and other LLMs via OpenAI-compatible APIs
5
5
  Project-URL: Homepage, https://github.com/can1357/llm-git
6
6
  Project-URL: Repository, https://github.com/can1357/llm-git
@@ -1,15 +1,15 @@
1
- lgit/__init__.py,sha256=0sKXfveoJIlBQMV434dWDgq3mCFuCYdqF9g0pFfnRgs,1767
1
+ lgit/__init__.py,sha256=TR3IZ6PdJXo_JKOmArwLDfeeO6DJoFhDN8F7HnbOQho,1767
2
2
  lgit/__main__.py,sha256=VbaRO8-0ehWv7zA27BpyHYWTQVvt5M-aG5HnWr7ws0U,165
3
3
  lgit/analysis.py,sha256=j8bduuV6pqvMuza-r_RNJDe5SMQGKTtU6gwktaAeSS4,10671
4
4
  lgit/api.py,sha256=GOx7mZNHfYgMq8_FKxlZcVgYiqK2cyQ6_ETHa9oclb8,33920
5
5
  lgit/cache.py,sha256=XCBWTslpT3NAqSu3H6K0m49HtyofaRUtzmgf_mCSbKw,10234
6
6
  lgit/changelog.py,sha256=uHMmL9Zw2B42_S0wk5LrltXmCVQMZgKzI1URgzcfdRU,15704
7
- lgit/cli.py,sha256=VSJ_e1edoccbAP94dLkWoF-28SgOtAkQc8_I5LWTYn8,46428
7
+ lgit/cli.py,sha256=tJhptV09ZXZfFRMaqiNFs8kJHUZ-wUrtF_nYCBDLi8E,47087
8
8
  lgit/compose.py,sha256=Sn9s2Q7cgP77_zJNKsLti2rZkuWXYF8vaplepG9lors,75764
9
9
  lgit/config.py,sha256=7Jd7adPtnOaiBAiXRFWk1aF4k7i5PlTD-uO_fDm-w-k,13958
10
10
  lgit/diffing.py,sha256=dVogyBNt8TzG-TaTTThwQEWora1Hnz1RuCUS5u18MNs,13289
11
- lgit/errors.py,sha256=KJXkXDfy0Qy3RfqoeMrvnolIokhGnv6fVVGXByz7fFg,3266
12
- lgit/git.py,sha256=HgwhewGnHjqQwIAuVuYGNDvEAaMU1FC9BbovbEWTD3Q,29010
11
+ lgit/errors.py,sha256=DkPJKA2ag5KbBoyuRk1d8zKgz9Mp1qRoLVBGRudlqkg,3457
12
+ lgit/git.py,sha256=SOhLXKqnSsqsirwjhFb9olNEuiQVWaqVrte7o3YTv-8,30744
13
13
  lgit/map_reduce.py,sha256=xoIxQUbb_NTNn5RSv5sdiVEQt9SpieWJM4WOsopwJlE,17484
14
14
  lgit/markdown_output.py,sha256=Oudlm09KjljvKbnQuteKLYHOlMK_JJJq2X8G7oRlX9E,26131
15
15
  lgit/models.py,sha256=hc3AJ37YXoLBGgSbdLQN5EEnDNViXf-wywlkUW92_Z8,28942
@@ -39,8 +39,8 @@ lgit/testing/compare.py,sha256=jRY98uLclVPyQ7e1TMqFVz2cjUi6kwwn2dkQyR_xsgY,1834
39
39
  lgit/testing/fixture.py,sha256=VXk02ZzFTBHHhYax6bsoGowdyz06nmrJm3ylenyfGbU,13654
40
40
  lgit/testing/report.py,sha256=wb7YnP_lsYwsg5OIFtsIC1bMHtK42Mttul_zQcwRNpk,9036
41
41
  lgit/testing/runner.py,sha256=5Sr4QvEOTdE7CAxB-CKcNJClEZARQGqB-t_6P6-UA2c,9514
42
- lgit_cli-4.1.0.dist-info/METADATA,sha256=hrJiCb8FEkbyDJ9C7U-cyypQYPi0HrH-ZrkOwlWQWng,9565
43
- lgit_cli-4.1.0.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
44
- lgit_cli-4.1.0.dist-info/entry_points.txt,sha256=CUSsokc0V3oVHQ2Z1ocL09wV7Krhm0SSfLZpnRMBdA0,39
45
- lgit_cli-4.1.0.dist-info/licenses/LICENSE,sha256=6dqVzjngLuIcUMd4wWLXPLpv-Pi8gySZAEE3hSN5iKw,1076
46
- lgit_cli-4.1.0.dist-info/RECORD,,
42
+ lgit_cli-4.2.0.dist-info/METADATA,sha256=Q3lXxEUzo6SXMGpyfEWl_ULmYKz3fo6_BrnMDoIpTM4,9565
43
+ lgit_cli-4.2.0.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
44
+ lgit_cli-4.2.0.dist-info/entry_points.txt,sha256=CUSsokc0V3oVHQ2Z1ocL09wV7Krhm0SSfLZpnRMBdA0,39
45
+ lgit_cli-4.2.0.dist-info/licenses/LICENSE,sha256=6dqVzjngLuIcUMd4wWLXPLpv-Pi8gySZAEE3hSN5iKw,1076
46
+ lgit_cli-4.2.0.dist-info/RECORD,,