Skip to content

Commit

Permalink
Merge pull request #554 from JrGoodle/git-alias
Browse files Browse the repository at this point in the history
Add git herd alias to project git configs when running clowder herd command
  • Loading branch information
JrGoodle committed May 30, 2020
2 parents 9d1cdb4 + 507af63 commit 1c89c39
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 12 deletions.
16 changes: 16 additions & 0 deletions src/clowder/git/project_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,12 @@ def herd(self, url: str, depth: int = 0, fetch: bool = True,

if not existing_git_repository(self.repo_path):
self._herd_initial(url, depth=depth)
self.install_project_git_herd_alias()
if config is not None:
self._update_git_config(config)
return

self.install_project_git_herd_alias()
if config is not None:
self._update_git_config(config)
self._create_remote(self.remote, url)
Expand All @@ -125,11 +127,13 @@ def herd_branch(self, url: str, branch: str, depth: int = 0, rebase: bool = Fals

if not existing_git_repository(self.repo_path):
self._herd_branch_initial(url, branch, depth=depth)
self.install_project_git_herd_alias()
if config is not None:
self._update_git_config(config)
return

if config is not None:
self.install_project_git_herd_alias()
self._update_git_config(config)

branch_output = fmt.ref_string(branch)
Expand Down Expand Up @@ -179,9 +183,11 @@ def herd_tag(self, url: str, tag: str, depth: int = 0,
self.herd(url, depth=depth, fetch=fetch, rebase=rebase)
return
else:
self.install_project_git_herd_alias()
if config is not None:
self._update_git_config(config)

self.install_project_git_herd_alias()
if config is not None:
self._update_git_config(config)
try:
Expand Down Expand Up @@ -212,6 +218,16 @@ def herd_remote(self, url: str, remote: str, branch: Optional[str] = None) -> No
LOG_DEBUG('Failed fetch', err)
self.fetch(remote, ref=self.default_ref)

def install_project_git_herd_alias(self) -> None:
"""Install 'git herd' alias for project"""

from clowder import CLOWDER_DIR
config_variable = 'alias.herd'
config_value = f'!clowder herd {self.repo_path.relative_to(CLOWDER_DIR)}'
self._print(" - Update git herd alias")
self.git_config_unset_all_local(config_variable)
self.git_config_add_local(config_variable, config_value)

def prune_branch_local(self, branch: str, force: bool) -> None:
"""Prune local branch
Expand Down
4 changes: 2 additions & 2 deletions src/clowder/model/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@ def __init__(self, project: dict, defaults: Defaults, sources: Tuple[Source, ...
message = fmt.error_remote_dup(self.fork.name, self.name, self.remote, CLOWDER_YAML)
raise ClowderError(ClowderErrorType.CLOWDER_YAML_DUPLICATE_REMOTE_NAME, message)

groups = ['all', self.name, str(Path(self.name).name), str(self.path)]
groups = ['all', self.name, str(self.path)]
if self._groups is not None:
groups += copy.deepcopy(self._groups)
if self.fork is not None:
groups += [self.fork.name, str(Path(self.fork.name).name)]
groups += [self.fork.name]
groups = list(set(groups))
if 'notdefault' in groups:
groups.remove('all')
Expand Down
24 changes: 24 additions & 0 deletions test/scripts/cats/git-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,27 @@ test_defaults_project_git_config() {
popd || exit 1
}
test_defaults_project_git_config

./clean.sh
./init.sh || exit 1

test_project_git_herd_alias() {
print_single_separator
echo "TEST: Custom git herd config alias in project"
begin_command
$COMMAND herd $PARALLEL || exit 1
end_command

echo "TEST: Custom git herd config alias in project is installed"
for project in "${all_projects[@]}"; do
pushd $project || exit 1
begin_command
git herd || exit 1
end_command
popd || exit 1
done

# TODO: Add test setting projects to a known older state, running 'git herd' on select projects,
# and validating that only the correct ones have been update
}
test_project_git_herd_alias
4 changes: 1 addition & 3 deletions test/scripts/cats/groups.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ test_groups_2() {
pushd mu || exit 1
test_branch knead
popd || exit 1
pushd mu-cat || exit 1
test_branch knead
popd || exit 1
test_no_directory_exists 'mu-cat'
test_no_directory_exists 'duke'
test_no_directory_exists 'black-cats'
}
Expand Down
8 changes: 4 additions & 4 deletions test/scripts/misc/forks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ cd "$MISC_EXAMPLE_DIR" || exit 1
./init.sh || exit 1

test_fork_groups_1() {
test_no_directory_exists 'sox-code'
test_no_directory_exists 'sox'
test_no_directory_exists 'djinni'
test_no_directory_exists 'gyp'
begin_command
$COMMAND herd JrGoodle/sox $PARALLEL || exit 1
end_command
pushd sox-code || exit 1
pushd sox || exit 1
test_branch 'master'
test_remote_url 'origin' 'git@github.com:JrGoodle/sox.git'
test_remote_url 'upstream' 'https://git.code.sf.net/p/sox/code.git'
Expand All @@ -41,13 +41,13 @@ test_fork_groups_1
./init.sh || exit 1

test_fork_groups_2() {
test_no_directory_exists 'sox-code'
test_no_directory_exists 'sox'
test_no_directory_exists 'djinni'
test_no_directory_exists 'gyp'
begin_command
$COMMAND herd sox $PARALLEL || exit 1
end_command
pushd sox-code || exit 1
pushd sox || exit 1
test_branch 'master'
test_remote_url 'origin' 'git@github.com:JrGoodle/sox.git'
test_remote_url 'upstream' 'https://git.code.sf.net/p/sox/code.git'
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/misc/sources.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ test_gyp_remotes() {
test_gyp_remotes

test_sox_remotes() {
pushd sox-code || exit 1
pushd sox || exit 1
test_remote_url 'origin' 'git@github.com:JrGoodle/sox.git'
test_remote_url 'upstream' 'https://git.code.sf.net/p/sox/code.git'
popd || exit 1
Expand Down
4 changes: 2 additions & 2 deletions test/scripts/misc/write_forks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ cd "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/.." || exit 1

export all_projects=( 'djinni' \
'gyp' \
'sox-code' )
'sox' )

export master_projects=( 'djinni' \
'sox-code' )
'sox' )

if [ "$ACCESS_LEVEL" == "write" ]; then
print_double_separator
Expand Down

0 comments on commit 1c89c39

Please sign in to comment.