Skip to content

Commit 4732152

Browse files
author
jgorostegui-veridas
committed
feat: add init command, bats test suite, and CI test job
1 parent cea829b commit 4732152

File tree

5 files changed

+431
-12
lines changed

5 files changed

+431
-12
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,12 @@ jobs:
1616
with:
1717
scandir: '.'
1818
severity: warning
19+
20+
test:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@v4
24+
- name: Install bats
25+
run: sudo apt-get install -y bats
26+
- name: Run tests
27+
run: bats tests/

README.md

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,21 @@ This:
7777
- Stores `.git` in `~/.git-dirs/GoogleDrive/dev/repo/`
7878
- Creates `.git-remote` with the URL (for other machines)
7979

80+
### Init a new repo in cloud folder
81+
82+
```bash
83+
cd ~/GoogleDrive/dev/new-project
84+
git-cloud init
85+
```
86+
87+
Or with a path:
88+
89+
```bash
90+
git-cloud init ~/GoogleDrive/dev/new-project
91+
```
92+
93+
This creates a new git repo with `.git` stored locally (no `git init` + `migrate` needed).
94+
8095
### Setup on another machine (after cloud sync)
8196

8297
Files arrive via cloud sync, but no `.git` yet:
@@ -117,25 +132,25 @@ Shows:
117132
┌─────────────────────────────────────────────────────────────────┐
118133
│ LAPTOP (first time) │
119134
│ │
120-
│ $ git-cloud clone git@github.com:me/project ~/GDrive/project │
135+
│ $ git-cloud clone git@github.com:me/project ~/GDrive/project
121136
│ │
122-
│ Cloud syncs: src/, .env, .git-remote │
123-
│ Local only: ~/.git-dirs/GDrive/project/ │
137+
│ Cloud syncs: src/, .env, .git-remote
138+
│ Local only: ~/.git-dirs/GDrive/project/
124139
└─────────────────────────────────────────────────────────────────┘
125140
126141
▼ (cloud sync)
127142
┌─────────────────────────────────────────────────────────────────┐
128143
│ DESKTOP (after sync) │
129144
│ │
130-
│ $ cd ~/GDrive/project │
131-
│ ⚠ Run 'git-cloud setup' to enable git │
145+
│ $ cd ~/GDrive/project
146+
│ ⚠ Run 'git-cloud setup' to enable git
132147
│ │
133-
│ $ git-cloud setup │
134-
│ Reading URL from .git-remote... │
135-
│ Done! │
148+
│ $ git-cloud setup
149+
│ Reading URL from .git-remote...
150+
│ Done!
136151
│ │
137-
│ $ git status │
138-
│ On branch main │
152+
│ $ git status
153+
│ On branch main
139154
└─────────────────────────────────────────────────────────────────┘
140155
```
141156

@@ -144,7 +159,9 @@ Shows:
144159
| Command | Description |
145160
|---------|-------------|
146161
| `git-cloud clone <url> [path]` | Clone with local `.git` storage |
162+
| `git-cloud init [path]` | Init new repo with local `.git` storage |
147163
| `git-cloud setup [url] [path]` | Setup git for synced folder |
164+
| `git-cloud sync [path]` | Sync local git with remote after cloud sync |
148165
| `git-cloud migrate [path]` | Move existing `.git` to local storage |
149166
| `git-cloud status` | Show all repos and their state |
150167
| `git-cloud help` | Show help |

git-cloud

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ set -e
77
GIT_DIRS="${GIT_DIRS:-$HOME/.git-dirs}"
88
CLOUD_DIRS="${CLOUD_DIRS:-$HOME/GoogleDrive:$HOME/Dropbox:$HOME/OneDrive}"
99
REMOTE_FILE=".git-remote"
10-
VERSION="1.3.0"
10+
VERSION="1.4.0"
1111

1212
# Colors
1313
red() { echo -e "\033[0;31m$1\033[0m"; }
@@ -86,6 +86,47 @@ cmd_clone() {
8686
echo "Tip: Add '$REMOTE_FILE' to your global .gitignore"
8787
}
8888

89+
# Init new repo with separate git dir
90+
cmd_init() {
91+
local repo_path="${1:-.}"
92+
93+
# Resolve to absolute path (create if needed)
94+
if [ ! -d "$repo_path" ]; then
95+
mkdir -p "$repo_path"
96+
fi
97+
repo_path="$(cd "$repo_path" && pwd)"
98+
99+
# Check if already a git repo
100+
if [ -d "$repo_path/.git" ] || [ -f "$repo_path/.git" ]; then
101+
red "Error: Already a git repository"
102+
echo "Use 'git-cloud migrate' to move .git to local storage"
103+
return 1
104+
fi
105+
106+
local git_dir
107+
git_dir=$(get_git_dir "$repo_path")
108+
109+
if [ -e "$git_dir" ]; then
110+
red "Error: Git dir already exists: $git_dir"
111+
echo "Remove it first: rm -rf \"$git_dir\""
112+
return 1
113+
fi
114+
115+
mkdir -p "$(dirname "$git_dir")"
116+
117+
blue "Initializing with separate git dir..."
118+
echo " Working tree: $repo_path"
119+
echo " Git dir: $git_dir"
120+
echo ""
121+
122+
git init --separate-git-dir="$git_dir" "$repo_path"
123+
124+
echo ""
125+
green "Done!"
126+
echo ""
127+
echo "Next: add a remote with 'git remote add origin <url>'"
128+
}
129+
89130
# Setup git for a folder that was synced (no .git yet)
90131
cmd_setup() {
91132
local arg1="$1"
@@ -461,6 +502,7 @@ SETUP (once per machine):
461502
462503
COMMANDS:
463504
git-cloud clone <url> [path] Clone repo with .git stored locally
505+
git-cloud init [path] Init new repo with .git stored locally
464506
git-cloud setup [url] [path] Setup git for synced folder
465507
git-cloud sync [path] Sync local git with remote after cloud sync
466508
git-cloud migrate [path] Move existing .git to local storage
@@ -487,6 +529,7 @@ EOF
487529
# Main
488530
case "${1:-}" in
489531
clone) cmd_clone "$2" "$3" ;;
532+
init) cmd_init "$2" ;;
490533
setup) cmd_setup "$2" "$3" ;;
491534
sync) cmd_sync "$2" ;;
492535
migrate) cmd_migrate "$2" ;;

install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ if ! grep -q '_git_cloud()' "$SHELL_RC" 2>/dev/null; then
9292
_git_cloud() {
9393
local cur="${COMP_WORDS[COMP_CWORD]}"
9494
if [ "$COMP_CWORD" -eq 1 ]; then
95-
COMPREPLY=($(compgen -W "clone setup migrate status version help" -- "$cur"))
95+
COMPREPLY=($(compgen -W "clone init setup sync migrate status version help" -- "$cur"))
9696
fi
9797
}
9898
complete -F _git_cloud git-cloud

0 commit comments

Comments
 (0)