Skip to content

Commit

Permalink
Merge branch 'release/0.1.10'
Browse files Browse the repository at this point in the history
  • Loading branch information
emlun committed May 5, 2017
2 parents bf9edfd + ed0442d commit 7e54974
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 25 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
0.1.10
=====

Version 0.1.9 is already used in unfinished development.

* Add `clone` command, which works like `update` but clones only those repos
named explicitly on the command line


0.1.8
=====

Expand Down
33 changes: 29 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,26 @@ Installation
* **Arch Linux**: Install the [gws](https://aur.archlinux.org/packages/gws/)
package from AUR

* **Other Linux/Mac**: You simply need to have the `src/gws` bash script
* **openSUSE**: Install the [gws](https://software.opensuse.org/package/gws/)
package from the devel:tools repository

* **Mac**:

* On Mac OS X, it may be necessary to upgrade bash to have a version `> 4.0`.
It could be done with: `brew install bash`.

* There is currently a [bug](https://github.com/StreakyCobra/gws/issues/17) in
version `0.1.8`. The script use some options that are specific to GNU's
`sed` and `cut`, which are not available to OS X versions. A workaround is
to install `coreutils` and `gnu-sed` with `brew` (`brew install gnu-sed
coreutils`) and then define the following alias inside your `~/.bashrc`
file:

```bash
alias gws="PATH=/usr/local/opt/coreutils/libexec/gnubin:usr/local/opt/gnu-sed/libexec/gnubin:$PATH gws"
```

* **Other Linux**: You simply need to have the `src/gws` bash script
somewhere inside your `$PATH`:

* If someone made a package for your distribution you are lucky.
Expand All @@ -40,8 +59,6 @@ Installation
`bash` you can include any directory on your `$PATH` by including `export
PATH="$PATH:/path/to/scripts/dir"` in your `~/.bashrc` file.

* On Mac OS X, it may be necessary to upgrade bash to have a version `> 4.0`.
It could be done with: `brew install bash`.

On a side note, I could also suggest you to have a look at
[peru](https://github.com/buildinspace/peru) which permits to keep files from
Expand Down Expand Up @@ -71,7 +88,8 @@ QuickStart

**and then**

* Clone all missing repositories with `gws update`.
* Clone all missing repositories with `gws update`, or some specific ones with
`gws clone`.

* Do some hacking.

Expand Down Expand Up @@ -172,6 +190,11 @@ This tool offers some functionalities, among which:

$ gws update

* It can also clone a specified selection of non-existing repositories from the
projects list, if you don't need all of them right now.
$ gws clone work/theSoftware
* It can monitor all listed repositories in one command (uncommitted changes,
untracked changes, branches not synced with origin, ...).
Expand Down Expand Up @@ -293,3 +316,5 @@ Many thanks to these people for contributions:
- Frédéric Mahé
- Blount
- Alex Sanchez
- Antoine Belvire
- Emil Lundberg
2 changes: 1 addition & 1 deletion completions/bash
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ _gws()
local cur="${COMP_WORDS[COMP_CWORD]}"

case $COMP_CWORD in
1) COMPREPLY=( $(compgen -S " " -W "init update status fetch ff check" -- $cur) $(compgen -S "/" -A directory -- "$cur") )
1) COMPREPLY=( $(compgen -S " " -W "init clone update status fetch ff check" -- $cur) $(compgen -S "/" -A directory -- "$cur") )
;;
2) COMPREPLY=( $(compgen -S "/" -A directory -- "$cur") )
;;
Expand Down
2 changes: 1 addition & 1 deletion completions/zsh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Zsh completion for gws

_path_or_command(){
_alternative 'cmds:commands:(init update status fetch ff check)' 'files:filenames:_path_files -/'
_alternative 'cmds:commands:(init clone update status fetch ff check)' 'files:filenames:_path_files -/'
}

_arguments "1::path or command:_path_or_command" "2::filenames:_path_files -/"
44 changes: 36 additions & 8 deletions src/gws
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# OS: Probably all linux distributions #
# Requirements: git, bash > 4.0 #
# License: MIT (See below) #
# Version: 0.1.8 #
# Version: 0.1.10 #
# #
# 'gws' is the abbreviation of 'Git WorkSpace'. #
# This is an helper to manage workspaces which contain git repositories. #
Expand Down Expand Up @@ -50,7 +50,7 @@ set -o pipefail
# {{{ Parameters

# Version number
VERSION="0.1.8"
VERSION="0.1.10"

# Starting directory
START_PWD="$(pwd)"
Expand Down Expand Up @@ -688,13 +688,18 @@ function cmd_init()
return 1
}

# Update command
function cmd_update()
# Selective clone command
function cmd_clone()
{
local dir repo remote remote_name remote_url

if [[ -z "$1" ]]; then
echo -e "Usage: ${C_RED}$(basename "$0")${C_OFF} ${C_BLUE}clone${C_OFF} ${C_GREEN}<directory>...${C_OFF}"
return 1
fi

# For all projects
for dir in "${projects_indexes[@]}"
for dir in "$@"
do
# Get informations about the current project
repo=$(get_repo_url "${projects[$dir]}")
Expand Down Expand Up @@ -747,6 +752,21 @@ function cmd_update()
return 0
}


# Update command
function cmd_update()
{
local dir

# For all projects
for dir in "${projects_indexes[@]}"
do
cmd_clone "$dir"
done

return 0
}

# Status command
function cmd_status()
{
Expand Down Expand Up @@ -969,6 +989,7 @@ function usage()
echo -e "where ${C_BLUE}<command>${C_OFF} is:"
echo -e " ${C_BLUE}init${C_OFF} - Detect the repositories and create the projects list"
echo -e " ${C_BLUE}update${C_OFF} - Update the workspace to get new repositories from projects list"
echo -e " ${C_BLUE}clone${C_OFF} - Selectively clone specific repositories from projects list"
echo -e " ${C_BLUE}status${C_OFF} - Print status for all repositories in the workspace"
echo -e " ${C_BLUE}fetch${C_OFF} - Print status for all repositories in the workspace, but fetch the origin before"
echo -e " ${C_BLUE}ff${C_OFF} - Print status for all repositories in the workspace, but fast forward from origin before"
Expand Down Expand Up @@ -1009,9 +1030,12 @@ if [[ "$1" != "init" ]]; then
# If a path is specified as second argument, limit projects to the ones matching
# the path
if [[ -n "$2" ]]; then
error_msg="${C_RED}The directory '$2' is not found.${C_OFF}"
projects_list=$(keep_prefixed_projects "$2") || (echo -e "$error_msg" && exit 1) || exit 1
projects_indexes=( ${projects_list} )
# But don't error out in the case of "clone", becuase the directory will probably not exist
if [[ "$1" != "clone" ]]; then
error_msg="${C_RED}The directory '$2' is not found.${C_OFF}"
projects_list=$(keep_prefixed_projects "$2") || (echo -e "$error_msg" && exit 1) || exit 1
projects_indexes=( ${projects_list} )
fi
fi
fi

Expand All @@ -1021,6 +1045,10 @@ case $1 in
"init")
cmd_init
;;
"clone")
shift
cmd_clone "$@"
;;
"update")
cmd_update
;;
Expand Down
4 changes: 3 additions & 1 deletion tests/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
Workspace/
Workspace/
Workspace_test_clone/
Workspace_test_update/
46 changes: 36 additions & 10 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ GWS_SCRIPT=$(PWD)/../src/gws

# Workspace folder name
WORKSPACE=Workspace
TEST_CLONE_WORKSPACE=$(WORKSPACE)_test_clone
TEST_UPDATE_WORKSPACE=$(WORKSPACE)_test_update

prepare:
$(MAKE) clean # Clean existing folder
Expand All @@ -15,21 +17,21 @@ $(WORKSPACE):
mkdir -p $(WORKSPACE)/{work,tools,ignoring}
git clone https://github.com/karpathy/neuraltalk.git $(WORKSPACE)/work/neuraltalk
git clone https://github.com/sameersbn/docker-gitlab.git $(WORKSPACE)/work/docker-gitlab
cd $(WORKSPACE)/work/docker-gitlab; git co gh-pages
cd $(WORKSPACE)/work/docker-gitlab; git checkout gh-pages
git clone https://github.com/harelba/q $(WORKSPACE)/tools/q
cd $(WORKSPACE)/tools/q; git co gh-pages
cd $(WORKSPACE)/tools/q; git checkout gh-pages
cd $(WORKSPACE)/tools/q; git remote add myone http://coool
cd $(WORKSPACE)/tools/q; git remote add upstream testurl
git clone https://github.com/buildinspace/peru $(WORKSPACE)/tools/peru
git clone https://github.com/dgorissen/coursera-dl $(WORKSPACE)/tools/coursera-dl
cd $(WORKSPACE)/tools/coursera-dl; git co master
cd $(WORKSPACE)/tools/coursera-dl; git checkout master
git init $(WORKSPACE)/tools/emptyyyy
git init $(WORKSPACE)/tools/another
cd $(WORKSPACE)/tools/another; \
git co -b aaaaabbbbbcccccdddddeeeeefffffggggghhhhhiiiiiccccc; \
touch test; git add test; git ci -m message
git checkout -b aaaaabbbbbcccccdddddeeeeefffffggggghhhhhiiiiiccccc; \
touch test; git add test; git commit -m message
git clone https://github.com/StreakyCobra/gws $(WORKSPACE)/ignoring/gws
cd $(WORKSPACE)/ignoring/gws; git co develop
cd $(WORKSPACE)/ignoring/gws; git checkout develop

$(WORKSPACE)/.ignore.gws: $(WORKSPACE)
echo "^ignoring/" > $@
Expand All @@ -39,12 +41,36 @@ $(WORKSPACE)/.project.gws: $(WORKSPACE)

perturbate:
cd $(WORKSPACE)/work/neuraltalk; touch test
cd $(WORKSPACE)/work/docker-gitlab; git co master; git reset --hard HEAD^
cd $(WORKSPACE)/tools/q; touch test; git add test; git ci -m message
cd $(WORKSPACE)/work/docker-gitlab; git checkout master; git reset --hard HEAD^
cd $(WORKSPACE)/tools/q; touch test; git add test; git commit -m message
cd $(WORKSPACE)/tools; rm -rf peru
cd $(WORKSPACE)/tools/coursera-dl; touch test; git add test

clean:
rm -rf $(WORKSPACE)
rm -rf $(WORKSPACE) $(TEST_CLONE_WORKSPACE) $(TEST_UPDATE_WORKSPACE)

.PHONY: tests perturbate test_project_gws test_status test_update test_check test_fetch test_ff clean
.PHONY: tests perturbate test_project_gws test_status test_clone test_update test_check test_fetch test_ff clean

tests: test_clone test_update

test_clone:
rm -rf $(TEST_CLONE_WORKSPACE)
mkdir -p rf $(TEST_CLONE_WORKSPACE)
cp test_update_projects.gws $(TEST_CLONE_WORKSPACE)/.projects.gws
cp test_update_ignore.gws $(TEST_CLONE_WORKSPACE)/.ignore.gws
cd $(TEST_CLONE_WORKSPACE); $(GWS_SCRIPT) clone ignoring/gws gws2 >/dev/null
# clone command clones only the named project, and overrides ignore settings
test -d $(TEST_CLONE_WORKSPACE)/ignoring/gws
test ! -d $(TEST_CLONE_WORKSPACE)/gws
test -d $(TEST_CLONE_WORKSPACE)/gws2

test_update:
rm -rf $(TEST_UPDATE_WORKSPACE)
mkdir -p rf $(TEST_UPDATE_WORKSPACE)
cp test_update_projects.gws $(TEST_UPDATE_WORKSPACE)/.projects.gws
cp test_update_ignore.gws $(TEST_UPDATE_WORKSPACE)/.ignore.gws
cd $(TEST_UPDATE_WORKSPACE); $(GWS_SCRIPT) update >/dev/null
# update command clones all projects except ignored ones
test ! -d $(TEST_UPDATE_WORKSPACE)/ignoring/gws
test -d $(TEST_UPDATE_WORKSPACE)/gws
test -d $(TEST_UPDATE_WORKSPACE)/gws2
1 change: 1 addition & 0 deletions tests/test_update_ignore.gws
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
^ignoring/
3 changes: 3 additions & 0 deletions tests/test_update_projects.gws
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ignoring/gws | https://github.com/StreakyCobra/gws
gws | https://github.com/StreakyCobra/gws
gws2 | https://github.com/StreakyCobra/gws

0 comments on commit 7e54974

Please sign in to comment.