xgem-cli 2.0.0-alpha.2 → 2.0.0-alpha.3

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.
package/lib/git.sh CHANGED
@@ -24,9 +24,13 @@ cmd_git_cmt() {
24
24
  die "Invalid choice. Operation aborted."
25
25
  fi
26
26
 
27
- log_info "Committing changes..."
28
- if ! git commit -m "$commit_msg"; then
29
- die "Commit failed. Aborting before pull/push."
27
+ if git diff --cached --quiet; then
28
+ log_warn "Nothing staged to commit checking whether there's anything already committed to sync."
29
+ else
30
+ log_info "Committing changes..."
31
+ if ! git commit -m "$commit_msg"; then
32
+ die "Commit failed. Aborting before pull/push."
33
+ fi
30
34
  fi
31
35
 
32
36
  local current_branch remote_name
@@ -38,14 +42,29 @@ cmd_git_cmt() {
38
42
  fi
39
43
 
40
44
  if [ -z "$remote_name" ]; then
41
- log_warn "Local commit dropped cleanly, but no remote is configured — sync was skipped."
45
+ log_warn "No remote configured — sync was skipped."
46
+ return 0
47
+ fi
48
+
49
+ local ahead_count
50
+ ahead_count=$(git rev-list --count "$remote_name/$current_branch..$current_branch" 2>/dev/null)
51
+ if [ "$ahead_count" = "0" ]; then
52
+ log_success "Already up to date with '$remote_name/$current_branch' — nothing to push."
42
53
  return 0
43
54
  fi
44
55
 
45
56
  log_info "Pulling updates from remote '$remote_name' on '$current_branch' via rebase..."
46
57
  if ! git pull --rebase "$remote_name" "$current_branch"; then
47
- log_error "MERGE CONFLICT DETECTED!"
48
- log_warn "Execution paused. Resolve conflicts to proceed."
58
+ local git_dir
59
+ git_dir=$(git rev-parse --git-dir 2>/dev/null)
60
+ if [ -d "$git_dir/rebase-merge" ] || [ -d "$git_dir/rebase-apply" ]; then
61
+ log_error "MERGE CONFLICT DETECTED!"
62
+ log_warn "Execution paused. Resolve conflicts to proceed."
63
+ else
64
+ log_error "Could not sync with '$remote_name' — this looks like a connection problem, not a merge conflict (see the git error above)."
65
+ log_warn "Your commit is safe locally. Re-run 'xgem git cmt' once connectivity is restored, or push manually: git push $remote_name $current_branch"
66
+ exit 1
67
+ fi
49
68
  local open_editor
50
69
  read -r -p "Do you want to open VS Code to resolve this now? (y/n): " open_editor
51
70
  [[ "$open_editor" == "y" || "$open_editor" == "Y" ]] && code .
package/lib-win/git.js CHANGED
@@ -41,25 +41,45 @@ async function cmdCmt(commitMsg) {
41
41
  die('Invalid choice. Operation aborted.');
42
42
  }
43
43
 
44
- logInfo('Committing changes...');
45
- const commitResult = git(['commit', '-m', commitMsg]);
46
- if (commitResult.status !== 0) {
47
- die('Commit failed. Aborting before pull/push.');
44
+ const hasStaged = spawnSync('git', ['diff', '--cached', '--quiet']).status !== 0;
45
+ if (!hasStaged) {
46
+ logWarn("Nothing staged to commit — checking whether there's anything already committed to sync.");
47
+ } else {
48
+ logInfo('Committing changes...');
49
+ const commitResult = git(['commit', '-m', commitMsg]);
50
+ if (commitResult.status !== 0) {
51
+ die('Commit failed. Aborting before pull/push.');
52
+ }
48
53
  }
49
54
 
50
55
  const currentBranch = gitCapture(['branch', '--show-current']);
51
56
  const remoteName = remoteExists('origin') ? 'origin' : gitCapture(['remote']).split(/\r?\n/)[0];
52
57
 
53
58
  if (!remoteName) {
54
- logWarn('Local commit dropped cleanly, but no remote is configured — sync was skipped.');
59
+ logWarn('No remote configured — sync was skipped.');
60
+ return;
61
+ }
62
+
63
+ const aheadCount = gitCapture(['rev-list', '--count', `${remoteName}/${currentBranch}..${currentBranch}`]);
64
+ if (aheadCount === '0') {
65
+ logSuccess(`Already up to date with '${remoteName}/${currentBranch}' — nothing to push.`);
55
66
  return;
56
67
  }
57
68
 
58
69
  logInfo(`Pulling updates from remote '${remoteName}' on '${currentBranch}' via rebase...`);
59
70
  const pullResult = git(['pull', '--rebase', remoteName, currentBranch]);
60
71
  if (pullResult.status !== 0) {
61
- logError('MERGE CONFLICT DETECTED!');
62
- logWarn('Execution paused. Resolve conflicts to proceed.');
72
+ const gitDir = gitCapture(['rev-parse', '--git-dir']);
73
+ const path = require('node:path');
74
+ const fs = require('node:fs');
75
+ const inConflict = fs.existsSync(path.join(gitDir, 'rebase-merge')) || fs.existsSync(path.join(gitDir, 'rebase-apply'));
76
+ if (inConflict) {
77
+ logError('MERGE CONFLICT DETECTED!');
78
+ logWarn('Execution paused. Resolve conflicts to proceed.');
79
+ } else {
80
+ logError(`Could not sync with '${remoteName}' — this looks like a connection problem, not a merge conflict (see the git error above).`);
81
+ logWarn(`Your commit is safe locally. Re-run 'xgem git cmt' once connectivity is restored, or push manually: git push ${remoteName} ${currentBranch}`);
82
+ }
63
83
  process.exit(1);
64
84
  }
65
85
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xgem-cli",
3
- "version": "2.0.0-alpha.2",
3
+ "version": "2.0.0-alpha.3",
4
4
  "description": "Framework-aware automation CLI: scaffolds and runs clean/build/dev scripts per project type, an environment doctor, a SwiftPM-aware iOS build engine, and a git workflow helper. Runs natively on macOS, Linux, and Windows.",
5
5
  "bin": {
6
6
  "xgem": "bin/xgem.js"