Skip to content
This repository was archived by the owner on Nov 23, 2025. It is now read-only.

Commit ad0477d

Browse files
author
David May
committed
GitSpaces v2 first release
1 parent a44c750 commit ad0477d

30 files changed

+828
-1060
lines changed

.cobra.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
author: David May <davfive@gmail.com>
2+
license: MIT
3+
useViper: true

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build
2+
gitspaces
3+
__debug*

.golangci.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
linters:
2+
disable-all: true
3+
enable:
4+
- govet
5+
- gofmt
6+
- revive
7+
- staticcheck
8+
- errcheck
9+
- nilerr
10+
- gosec
11+
12+
# Path: .golangci.yml

.vscode/launch.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "gitspaces create",
9+
"type": "go",
10+
"request": "launch",
11+
"mode": "auto",
12+
"program": "${workspaceFolder}",
13+
"cwd": "/Users/davidmay/code/davfive/testarea",
14+
"args": ["create", "https://github.com/davfive/gitspaces2.git", "-n", "3"],
15+
"console": "integratedTerminal"
16+
},
17+
{
18+
"name": "gitspaces switch",
19+
"type": "go",
20+
"request": "launch",
21+
"mode": "auto",
22+
"program": "${workspaceFolder}",
23+
"cwd": "/Users/davidmay/code/davfive",
24+
"args": ["switch"],
25+
"console": "integratedTerminal"
26+
},
27+
{
28+
"name": "gitspaces <empty>",
29+
"type": "go",
30+
"request": "launch",
31+
"mode": "auto",
32+
"program": "${workspaceFolder}",
33+
"cwd": "/Users/davidmay/code/davfive/testarea",
34+
"args": [],
35+
"console": "integratedTerminal"
36+
}
37+
]
38+
}

.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"go.lintTool": "golangci-lint",
3+
"go.lintFlags": [
4+
"[\"--fast\"]"
5+
]
6+
}

LICENSE

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +0,0 @@
1-
MIT License
2-
3-
Copyright (c) 2019 David May
4-
5-
Permission is hereby granted, free of charge, to any person obtaining a copy
6-
of this software and associated documentation files (the "Software"), to deal
7-
in the Software without restriction, including without limitation the rights
8-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9-
copies of the Software, and to permit persons to whom the Software is
10-
furnished to do so, subject to the following conditions:
11-
12-
The above copyright notice and this permission notice shall be included in all
13-
copies or substantial portions of the Software.
14-
15-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.

README.md

Lines changed: 1 addition & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -2,133 +2,4 @@
22

33
# gitspaces - A git development workspace manager
44

5-
> NOTE: I am calling all things "scripts". They are actually no scripts at all that are called from the cmdline. They are all bash aliases and functions, but to have one word, I call everything scripts.
6-
7-
## Upcoming Work
8-
9-
- [ ] Convert bash scripts into either python or golang with a light shell wrapper (to support changing directories)
10-
11-
## Overview
12-
13-
GitSpaces is a set of bash scripts for managing git-based development workspaces. The main features are
14-
15-
1. Space management
16-
* Multiple spaces
17-
* Multiple repositories per space
18-
* Space hibernation
19-
* Space renaming
20-
* Per user, space configuration overrides
21-
2. Cross-repository branch management
22-
* Common Development aids (multi-repo branch sets for ensuring on Development/Production/... branches)
23-
* Common (and uncommon) git alias
24-
* Directory change aliases (to each repository)
25-
* Visual Studio Code per workspace
26-
27-
## Background
28-
29-
The general idea is that for any given project you might be working on a feature here, a hotfix there, another feature there,
30-
and a bugfix somewhere else. You may handle all of these "concurrent" activities by forcing yourself to commit on your branch,
31-
change branches, or stash stuff. I've found that to be a lot of overhead especially if you are coordinating this across multiple
32-
repositories in a project.
33-
34-
For those of you with a, ahem, ClearCase background, you're familiar with the concept of ClearCase Views. Essentially it's an
35-
isolated workspace that has all of your project code where you can work on ONE THING. If you are asked to fix a bug or
36-
something else concurrently, you just create a new view (they're cheap) and work there. Unfortunately, git has no concept
37-
like this. Clones are expensive, committing just to context switch is a pain and messes up your commit history to boot.
38-
39-
Gitspaces are essentially a lightweight implementation of ClearCase Views for git projects.
40-
41-
## Command overview
42-
43-
Once gitspaces scripts are available in your environment, all gitspaces commands are prefixed with `gs`. e.g.
44-
45-
Command | Description
46-
------------|------------------------
47-
`gs switch` | Switch to a different top-level gitspace project.
48-
`gs ls` | List repository information (e.g., what branch they are on)
49-
`gs mv` | Rename a current gitspace
50-
`gs sleep` | Archive a gitspace (not using it currently - renames to _.zzz-# and hides from lists)
51-
`gs cd` | cd around a gitspaces project. Switch gitspace, repos, folder
52-
`gs cd -` | Switch to a different gitspace (allows you wake one up you put to sleep to use fresh)
53-
`gs co` | Choose from a list of 'BranchSet's (in gsconfig.ini) and will git pull each repos to it's specified branch
54-
`gs code` | Launches Visual Studio Code with .code-workspace file updated with proper paths for debugging
55-
`gs init` | _TODO_: Creates project gitspaces.ini, spaces-dir, and first gs space folder (firstspace)
56-
`gs cp` | _TODO_: Copies an existing gitspace folder to create another (and puts it to sleep)
57-
58-
59-
## Quick Setup
60-
61-
1. Download/Clone gitspaces repo and add it to your .bashrc file
62-
63-
```
64-
cd ~
65-
git clone <repo-path> .gitspaces
66-
echo ". ~/.gitspaces/gitspaces.sh" >> ~/.bashrc
67-
cp ~/.gitspaces/userfiles/.gitspacesrc.sh ~/
68-
perl -pi -e "s/^#alias/alias/ ~/.gitspacesrc.sh # aliases gs=gitspaces, cds='gs cd'
69-
. ~/.bashrc
70-
```
71-
72-
2. Create a code project folder (will house projectA's gitspaces)
73-
74-
```
75-
mkdir -p ~/code/projectA
76-
```
77-
78-
3. Setup a GitSpaces project folder
79-
> Future: this is what 'gs init' will do
80-
```
81-
cd ~/code/projectA
82-
cp ~/.gitspaces/userfiles/gitspaces.ini . # See file comments for details
83-
mkdir $GITSPACES_SPACESDIR # defaults to '_' # Where all of your project spaces will live
84-
mkdir -p $GITSPACES_SPACESDIR/firstspace # First project space, you can rename it later
85-
cd $GITSPACES_SPACESDIR/firstspace
86-
87-
# A GitSpaces project folder has the following structure:
88-
~/code/projectA/
89-
|- gitspaces.ini
90-
|- _/
91-
+- space-1/
92-
+- projectA-repo-1
93-
...
94-
+- projectA-repo-N
95-
...
96-
+- space-N/
97-
+- projectA-repo-1
98-
...
99-
+- projectA-repo-N
100-
```
101-
102-
4. Clone all of your repositories into the \_.first gitspace folder
103-
104-
```
105-
cd ~/code/projectA/_/firstspace
106-
git clone <projectA-repo1>
107-
...
108-
git clone <projectA-repoN>
109-
```
110-
111-
5. Create additional GitSpaces for projectA
112-
> Simply 'cp -R firstspace secondspace' (way faster usually than re-cloning)
113-
> Note the copy operation is way quicker if you clean your firstspace repos' (git clean -dx -f)
114-
```
115-
cd ~/code/projectA
116-
cp -R firstspace secondspace
117-
...
118-
cp -R firstspace nthspace
119-
```
120-
121-
You can add a new gitspace folder anytime you want when you need more. I've generally found that 5 are sufficient.
122-
123-
6. Add your new GitSpaces project to GITSPACES_PROJDIRS in ~/.gitspacesrc.sh and resource
124-
125-
7. Start using GitSpaces
126-
127-
8. Optional: Include ~/.gitspaces/userfiles/gitconfig
128-
129-
My common git aliases are in the userfiles folder. Just add the following to your ~/.gitconfig
130-
131-
```
132-
[include]
133-
path = ~/.gitspaces/userfiles/gitconfig
134-
```
5+
TODO update docs for v2 (golang, simplified, edition)

cmd/code.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package cmd
2+
3+
import (
4+
"gitspaces/internal/console"
5+
"gitspaces/internal/gitspaces"
6+
7+
"github.com/spf13/cobra"
8+
)
9+
10+
// codeCmd represents the code command
11+
var codeCmd = &cobra.Command{
12+
Use: "code",
13+
Short: "Open space as a workspace in Visual Studio Code",
14+
Args: cobra.NoArgs,
15+
RunE: func(cmd *cobra.Command, args []string) error {
16+
space, err := gitspaces.GetSpace()
17+
if err != nil {
18+
return err
19+
}
20+
21+
if err = space.OpenVSCode(); err != nil {
22+
return console.Errorln("Failed to open Visual Studio Code: %s", err)
23+
}
24+
return nil
25+
},
26+
}
27+
28+
func init() {
29+
rootCmd.AddCommand(codeCmd)
30+
}

cmd/create.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
6+
"gitspaces/internal/console"
7+
"gitspaces/internal/gitspaces"
8+
"gitspaces/internal/helper"
9+
10+
"github.com/spf13/cobra"
11+
)
12+
13+
// createCmd represents the create command
14+
var createCmd = &cobra.Command{
15+
Use: "create [flags] URL [DIR]",
16+
Short: "Creates a GitSpace from the provided repo url",
17+
Long: "Creates a GitSpace from the provided repo url.",
18+
Args: func(cmd *cobra.Command, args []string) error {
19+
if len(args) < 1 {
20+
return fmt.Errorf("requires a URL argument")
21+
}
22+
if len(args) > 2 {
23+
return fmt.Errorf("unexpected positional arguments after URL [DIR]")
24+
}
25+
return nil
26+
},
27+
RunE: func(cmd *cobra.Command, args []string) (err error) {
28+
url := args[0]
29+
dir := helper.GetStringAtIndex(args, 1, "")
30+
numClones, _ := cmd.Flags().GetInt("num_clones")
31+
32+
var project *gitspaces.ProjectStruct
33+
var space *gitspaces.SpaceStruct
34+
35+
if project, err = gitspaces.CreateProject(url, dir, numClones); err != nil {
36+
return err
37+
}
38+
39+
if space, err = project.WakeupSpace(); err != nil {
40+
return err
41+
}
42+
43+
console.Println("\nCreated GitSpace at '%s' with %d clones", project.Path, numClones)
44+
45+
gitspaces.User.WriteCdToPath(space.Path)
46+
return nil
47+
},
48+
}
49+
50+
func init() {
51+
rootCmd.AddCommand(createCmd)
52+
createCmd.Flags().IntP("num_clones", "n", 3, "Number of sleeper clones to create")
53+
}

cmd/rename.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
3+
*/
4+
package cmd
5+
6+
import (
7+
"gitspaces/internal/console"
8+
"gitspaces/internal/gitspaces"
9+
10+
"github.com/spf13/cobra"
11+
)
12+
13+
// renameCmd represents the rename command
14+
var renameCmd = &cobra.Command{
15+
Use: "rename",
16+
Short: "Rename the current space",
17+
Long: `Rename the current space`,
18+
RunE: func(cmd *cobra.Command, args []string) (err error) {
19+
space, err := gitspaces.GetSpace()
20+
if err != nil {
21+
return err
22+
}
23+
24+
if err = space.Rename(); err != nil {
25+
return console.Errorln("Failed to rename space: %s", err)
26+
}
27+
28+
gitspaces.User.WriteCdToPath(space.Path)
29+
return nil
30+
},
31+
}
32+
33+
func init() {
34+
rootCmd.AddCommand(renameCmd)
35+
}

0 commit comments

Comments
 (0)