gitbash 0.1.0

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.
@@ -0,0 +1,191 @@
1
+ # Update the current branch with the latest version of master/main
2
+ update() {
3
+ local merge_tool="${GITBASH_FEATURE_BRANCH_PREFIX:-}"
4
+ local should_push=false
5
+
6
+ # Parse arguments
7
+ while [[ $# -gt 0 ]]; do
8
+ case $1 in
9
+ -h|--help)
10
+ cat << 'EOF'
11
+ Usage: update [OPTIONS]
12
+
13
+ Update the current feature branch with the latest changes from main/master.
14
+
15
+ Options:
16
+ -p, --push Push to origin after successful merge
17
+ -h, --help Show this help message
18
+
19
+ Configuration:
20
+ - Merge tool can be set by editing the 'GITBASH_MERGE_COMMAND' variable
21
+ - Default: "fork"
22
+
23
+ Behavior:
24
+ 1. Detects whether your repo uses 'main' or 'master'
25
+ 2. Fetches the latest base branch from origin
26
+ 3. Merges it into your current branch
27
+ 4. Optionally pushes the updated branch to origin
28
+ 5. Opens merge tool if conflicts occur
29
+
30
+ Examples:
31
+ $ git checkout feature/LOVE-123-new-feature
32
+ $ update
33
+ Fetching latest 'main' from origin...
34
+ Merging updated 'main' into 'feature/LOVE-123-new-feature'...
35
+ ✓ 'feature/LOVE-123-new-feature' is now up-to-date with 'main'.
36
+
37
+ ---
38
+
39
+ $ update --push
40
+ Fetching latest 'main' from origin...
41
+ Merging updated 'main' into 'feature/LOVE-123-new-feature'...
42
+ ✓ 'feature/LOVE-123-new-feature' is now up-to-date with 'main'.
43
+ Pushing 'feature/LOVE-123-new-feature' to origin...
44
+ ✓ Successfully pushed 'feature/LOVE-123-new-feature' to origin.
45
+
46
+ ---
47
+
48
+ $ update -p
49
+ Fetching latest 'main' from origin...
50
+ Merging updated 'main' into 'feature/dev-branch'...
51
+ ⚠ Merge completed with conflicts. Resolve them manually.
52
+ # Opens configured merge tool for conflict resolution
53
+
54
+ Configuration:
55
+ - Merge tool can be changed by editing the 'GITBASH_MERGE_COMMAND' variable
56
+ - Options: "fork", "code", "gitkraken", "gitk", etc.
57
+
58
+ Requirements:
59
+ - Must be in a git repository
60
+ - Must be on a feature branch (not main/master)
61
+ - Remote 'origin' must exist
62
+
63
+ Notes:
64
+ - Uses fast-forward merge when possible
65
+ - Automatically opens merge tool if conflicts occur
66
+ - Local main/master is updated without checkout
67
+
68
+ EOF
69
+ return 0
70
+ ;;
71
+ -p|--push)
72
+ should_push=true
73
+ shift
74
+ ;;
75
+ *)
76
+ echo "Unknown option: $1"
77
+ echo "Usage: update [-p|--push]"
78
+ return 1
79
+ ;;
80
+ esac
81
+ done
82
+
83
+ # Ensure we're in a git repo
84
+ if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
85
+ echo "Not inside a git repository."
86
+ return 1
87
+ fi
88
+
89
+ current_branch=$(git rev-parse --abbrev-ref HEAD)
90
+
91
+ # Detect base branch: main or master
92
+ if git show-ref --verify --quiet refs/heads/main; then
93
+ base_branch="main"
94
+ elif git show-ref --verify --quiet refs/heads/master; then
95
+ base_branch="master"
96
+ else
97
+ echo "Could not detect 'main' or 'master' locally."
98
+ return 1
99
+ fi
100
+
101
+ if [[ "$current_branch" == "$base_branch" ]]; then
102
+ # Already on main/master - just pull the latest changes
103
+ echo "Pulling latest changes for '$base_branch' from origin..."
104
+ git pull origin "$base_branch"
105
+
106
+ if [[ $? -eq 0 ]]; then
107
+ echo "✓ '$base_branch' is now up-to-date."
108
+ else
109
+ echo "⚠ Failed to pull latest changes."
110
+ return 1
111
+ fi
112
+ return 0
113
+ fi
114
+
115
+ # Check for uncommitted changes before merging
116
+ if [[ -n "$(git status --porcelain)" ]]; then
117
+ echo ""
118
+ echo "You have uncommitted changes:"
119
+ git status --short
120
+ echo ""
121
+ read -rp "Commit changes before updating? (Y/n): " reply
122
+ if [[ "$reply" =~ ^[Nn]$ ]]; then
123
+ echo "⚠ Cannot merge with uncommitted changes. Commit or stash them first."
124
+ return 1
125
+ fi
126
+ commit
127
+ if [[ $? -ne 0 ]]; then
128
+ echo "⚠ Commit failed. Aborting update."
129
+ return 1
130
+ fi
131
+ fi
132
+
133
+ echo "Fetching latest '$base_branch' from origin..."
134
+ git fetch origin "$base_branch:$base_branch" || {
135
+ echo "⚠ Could not fast-forward local '$base_branch'."
136
+ return 1
137
+ }
138
+
139
+ echo "Merging updated '$base_branch' into '$current_branch'..."
140
+ git merge --ff --no-edit "$base_branch"
141
+
142
+ if [[ $? -eq 0 ]]; then
143
+ echo "✓ '$current_branch' is now up-to-date with '$base_branch'."
144
+
145
+ # Push if requested and merge was successful
146
+ if [[ "$should_push" == true ]]; then
147
+ # Check if remote has updates and pull first
148
+ git fetch origin "$current_branch" 2>/dev/null
149
+ local local_commit=$(git rev-parse HEAD)
150
+ local remote_commit=$(git rev-parse "origin/$current_branch" 2>/dev/null)
151
+
152
+ if [[ -n "$remote_commit" && "$local_commit" != "$remote_commit" ]]; then
153
+ # Check if we're behind the remote
154
+ if git merge-base --is-ancestor "$local_commit" "$remote_commit" 2>/dev/null; then
155
+ echo "Remote has updates. Pulling first..."
156
+ git pull --rebase origin "$current_branch"
157
+ if [[ $? -ne 0 ]]; then
158
+ echo "⚠ Failed to pull remote changes. Please resolve conflicts and try again."
159
+ return 1
160
+ fi
161
+ echo "✓ Pulled latest changes."
162
+ elif ! git merge-base --is-ancestor "$remote_commit" "$local_commit" 2>/dev/null; then
163
+ # Branches have diverged
164
+ echo "Remote has diverged. Pulling with rebase..."
165
+ git pull --rebase origin "$current_branch"
166
+ if [[ $? -ne 0 ]]; then
167
+ echo "⚠ Failed to pull remote changes. Please resolve conflicts and try again."
168
+ return 1
169
+ fi
170
+ echo "✓ Rebased on latest changes."
171
+ fi
172
+ fi
173
+
174
+ echo "Pushing '$current_branch' to origin..."
175
+ git push origin "$current_branch"
176
+ if [[ $? -eq 0 ]]; then
177
+ echo "✓ Successfully pushed '$current_branch' to origin."
178
+ else
179
+ echo "⚠ Failed to push '$current_branch' to origin."
180
+ return 1
181
+ fi
182
+ fi
183
+ else
184
+ echo "⚠ Merge completed with conflicts. Resolve them manually."
185
+
186
+ # Open merge tool for conflict resolution
187
+ if command -v "$merge_tool" >/dev/null 2>&1; then
188
+ "$merge_tool" .
189
+ fi
190
+ fi
191
+ }
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "gitbash",
3
+ "version": "0.1.0",
4
+ "description": "Opinionated git utilities for bash with fzf-powered menus",
5
+ "author": "jaggli",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/jaggli/gitbash.git"
10
+ },
11
+ "homepage": "https://github.com/jaggli/gitbash#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/jaggli/gitbash/issues"
14
+ },
15
+ "keywords": [
16
+ "bash",
17
+ "git",
18
+ "fzf",
19
+ "shell",
20
+ "utilities",
21
+ "cli",
22
+ "branch",
23
+ "commit",
24
+ "stash"
25
+ ],
26
+ "bin": {
27
+ "gitbash": "bin/gitbash"
28
+ },
29
+ "files": [
30
+ "bin/",
31
+ "commands/",
32
+ "README.md",
33
+ "LICENSE"
34
+ ],
35
+ "os": [
36
+ "darwin",
37
+ "linux"
38
+ ],
39
+ "engines": {
40
+ "node": ">=14"
41
+ }
42
+ }