From f668552b53c6258f539e79b868eec78be83306dc Mon Sep 17 00:00:00 2001 From: Raphael Cohn Date: Tue, 28 Apr 2015 08:38:44 +0000 Subject: [PATCH 01/14] Change to clone --- git.functions | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/git.functions b/git.functions index a1dd80d..32156f2 100644 --- a/git.functions +++ b/git.functions @@ -236,7 +236,7 @@ git_cherrypicks() git_inRepositorySilently "$repositoryFolderPath" cherry-pick --strategy=recursive -X theirs "$@" } -git_addGitHubClone() +git_addGitHubCloneOrFetchFromOriginRemote() { local repositoryParentPath="$1" local repositoryUser="$2" @@ -245,6 +245,8 @@ git_addGitHubClone() local repositoryFolderPath="$repositoryParentPath"/"$repositoryName" if [ -d "$repositoryFolderPath"/.git ]; then + git_inRepositorySilently "$repositoryFolderPath" submodule update --init --recursive + git_fetchFromOriginRemote "$repositoryFolderPath" return 0 fi @@ -258,11 +260,9 @@ git_addGitHubClone() pushd "$repositoryParentPath" - git_withOutputSilencedIfQuiet 2 clone git@github.com:"$repositoryUser"/"$repositoryName".git + git_withOutputSilencedIfQuiet 2 clone --recursive git@github.com:"$repositoryUser"/"$repositoryName".git popd - - git_inRepositorySilently "$repositoryFolderPath" submodule update --init --recursive } git_addGitHubSubmodule() From e2ec5eaed842f81de7c6362f79fd0441d5e2aed5 Mon Sep 17 00:00:00 2001 From: Raphael Cohn Date: Tue, 5 May 2015 15:35:43 +0000 Subject: [PATCH 02/14] Adjustment --- git.functions | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/git.functions b/git.functions index 32156f2..3cf1777 100644 --- a/git.functions +++ b/git.functions @@ -239,8 +239,7 @@ git_cherrypicks() git_addGitHubCloneOrFetchFromOriginRemote() { local repositoryParentPath="$1" - local repositoryUser="$2" - local repositoryName="$3" + local cloneUrl="$2" local repositoryFolderPath="$repositoryParentPath"/"$repositoryName" @@ -260,7 +259,7 @@ git_addGitHubCloneOrFetchFromOriginRemote() pushd "$repositoryParentPath" - git_withOutputSilencedIfQuiet 2 clone --recursive git@github.com:"$repositoryUser"/"$repositoryName".git + git_withOutputSilencedIfQuiet 2 clone --recursive "$cloneUrl" popd } @@ -359,7 +358,7 @@ git_fetchFromRemote() local repositoryFolderPath="$1" local remote="$2" - git_inRepositorySilently "$repositoryFolderPath" fetch "$remote" + git_inRepositorySilently "$repositoryFolderPath" fetch --tags "$remote" } core_dependency_requires '*' git From 053eae61ecc4759f98533bde818843aefa7cee47 Mon Sep 17 00:00:00 2001 From: Raphael Cohn Date: Tue, 5 May 2015 15:36:15 +0000 Subject: [PATCH 03/14] Adjustment --- git.functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git.functions b/git.functions index 3cf1777..4c6400b 100644 --- a/git.functions +++ b/git.functions @@ -236,7 +236,7 @@ git_cherrypicks() git_inRepositorySilently "$repositoryFolderPath" cherry-pick --strategy=recursive -X theirs "$@" } -git_addGitHubCloneOrFetchFromOriginRemote() +git_addGitCloneOrFetchFromOriginRemote() { local repositoryParentPath="$1" local cloneUrl="$2" From d0606783258428c4c16a3163161a69c884e9e087 Mon Sep 17 00:00:00 2001 From: Raphael Cohn Date: Tue, 5 May 2015 15:42:25 +0000 Subject: [PATCH 04/14] Updated --- git.functions | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/git.functions b/git.functions index 4c6400b..8198a4c 100644 --- a/git.functions +++ b/git.functions @@ -240,6 +240,7 @@ git_addGitCloneOrFetchFromOriginRemote() { local repositoryParentPath="$1" local cloneUrl="$2" + local folderName="$3" local repositoryFolderPath="$repositoryParentPath"/"$repositoryName" @@ -259,7 +260,7 @@ git_addGitCloneOrFetchFromOriginRemote() pushd "$repositoryParentPath" - git_withOutputSilencedIfQuiet 2 clone --recursive "$cloneUrl" + git_withOutputSilencedIfQuiet 2 clone --recursive "$cloneUrl" "$folderName" popd } From a9f803ddfe14bbce8a02ac1d93ef27579e7f70f7 Mon Sep 17 00:00:00 2001 From: Raphael Cohn Date: Tue, 5 May 2015 18:30:30 +0000 Subject: [PATCH 05/14] Fix --- git.functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git.functions b/git.functions index 8198a4c..e7f5438 100644 --- a/git.functions +++ b/git.functions @@ -242,7 +242,7 @@ git_addGitCloneOrFetchFromOriginRemote() local cloneUrl="$2" local folderName="$3" - local repositoryFolderPath="$repositoryParentPath"/"$repositoryName" + local repositoryFolderPath="$repositoryParentPath"/"$folderName" if [ -d "$repositoryFolderPath"/.git ]; then git_inRepositorySilently "$repositoryFolderPath" submodule update --init --recursive From c1b89464308b9a85d8b44b7fc4e88f7d6f46d844 Mon Sep 17 00:00:00 2001 From: Raphael Cohn Date: Wed, 6 May 2015 08:28:55 +0000 Subject: [PATCH 06/14] Improvements --- git.functions | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/git.functions b/git.functions index e7f5438..8ce0736 100644 --- a/git.functions +++ b/git.functions @@ -210,6 +210,25 @@ git_tagUpstream() git_tag "$repositoryFolderPath" "$upstreamTagName" "$upstreamTagMessage" } +core_dependency_requires '*' git md5sum +git_localModificationHashOrEmptyString() +{ + local repositoryFolderPath="$1" + + local hashSum + local notWanted + read -r hashSum notWanted <<-EOF + $(git_inRepository "$repositoryFolderPath" diff --minimal --no-color | md5sum) + EOF + + local emptyStringHash='da89c63b0ea43b06a5bc547d66a13b75' + if [ "$hashSum" = "$emptyStringHash" ]; then + printf '' + else + printf '%s' "$hashSum" + fi +} + core_dependency_requires '*' cat git_patchAm() { From d5a5e3ff1657896666c0ba2e77d3580e57de521a Mon Sep 17 00:00:00 2001 From: Raphael Cohn Date: Wed, 6 May 2015 18:34:18 +0000 Subject: [PATCH 07/14] fix --- git.functions | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/git.functions b/git.functions index 8ce0736..99ebd57 100644 --- a/git.functions +++ b/git.functions @@ -218,10 +218,10 @@ git_localModificationHashOrEmptyString() local hashSum local notWanted read -r hashSum notWanted <<-EOF - $(git_inRepository "$repositoryFolderPath" diff --minimal --no-color | md5sum) + $(git_inRepository "$repositoryFolderPath" git diff --minimal --no-color | md5sum) EOF - local emptyStringHash='da89c63b0ea43b06a5bc547d66a13b75' + local emptyStringHash='d41d8cd98f00b204e9800998ecf8427e' if [ "$hashSum" = "$emptyStringHash" ]; then printf '' else From 757d537fa94beff65ba92466e3434726b8ecf6cc Mon Sep 17 00:00:00 2001 From: Raphael Cohn Date: Tue, 6 Oct 2015 11:19:29 +0100 Subject: [PATCH 08/14] added more functions --- README.md | 2 +- git.functions | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index dbe653a..9c1e704 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ This module provides a simple set of wrapper functions for making it more pleasa ## Overview -Usage couldn't be simpler. Just pick a function. +Usage couldn't be simpler. Just pick a function. Please note that most functions are not currently documented. ## Importing diff --git a/git.functions b/git.functions index 99ebd57..f1a4fd5 100644 --- a/git.functions +++ b/git.functions @@ -53,6 +53,59 @@ git_doesNotHaveTagPattern() fi } +core_dependency_requires '*' git +git_isPathSomewhereInsideGitRepository() +{ + local repositoryFolderPath="$1" + + pushd "$repositoryFolderPath" + + set +e + git log -n 0 2>/dev/null + local exitCode=$? + set -e + + popd + + return $exitCode +} + +# If in a submodule, walks up the directory hierarchy to the '.git' folder +# If no repository found, returns '' +git_findAbsolutePathOfTopLevelOfRepository() +{ + local repositoryFolderPath="$1" + + pushd "$repositoryFolderPath" + + local currentFolderPath="$(pwd)" + + popd + + while [ ! core_path_isReadableAndSearchableFolderPath "$currentFolderPath"/.git ]; then + do + if [ "$currentFolderPath" = '/' ]; then + printf '' + return 0 + fi + + pushd "$currentFolderPath"/.. + currentFolderPath="$(pwd)" + popd + done + + printf '%s' "$currentFolderPath" +} + +core_dependency_requires '*' grep +git_hasRemote() +{ + local repositoryFolderPath="$1" + local remoteName="$2" + + git_inRepository "$repositoryFolderPath" remote | grep -q '^'"$remoteName"'$' +} + git_checkout() { local repositoryFolderPath="$1" From 9cf86e5f4a13b6f2cd0c06e76207793906c38815 Mon Sep 17 00:00:00 2001 From: Raphael Cohn Date: Tue, 6 Oct 2015 17:30:46 +0100 Subject: [PATCH 09/14] bugfix --- git.functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git.functions b/git.functions index f1a4fd5..792069a 100644 --- a/git.functions +++ b/git.functions @@ -82,7 +82,7 @@ git_findAbsolutePathOfTopLevelOfRepository() popd - while [ ! core_path_isReadableAndSearchableFolderPath "$currentFolderPath"/.git ]; then + while [ ! core_path_isReadableAndSearchableFolderPath "$currentFolderPath"/.git ] do if [ "$currentFolderPath" = '/' ]; then printf '' From 99ae398470151555d6477346f5f038d1a7d96330 Mon Sep 17 00:00:00 2001 From: Raphael Cohn Date: Tue, 6 Oct 2015 17:40:42 +0100 Subject: [PATCH 10/14] bugfix --- git.functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git.functions b/git.functions index 792069a..8b4f85d 100644 --- a/git.functions +++ b/git.functions @@ -82,7 +82,7 @@ git_findAbsolutePathOfTopLevelOfRepository() popd - while [ ! core_path_isReadableAndSearchableFolderPath "$currentFolderPath"/.git ] + while ! core_path_isReadableAndSearchableFolderPath "$currentFolderPath"/.git do if [ "$currentFolderPath" = '/' ]; then printf '' From a576a264d382c290d25ec2e3c35aba9257e49ad1 Mon Sep 17 00:00:00 2001 From: Raphael Cohn Date: Tue, 6 Oct 2015 18:10:58 +0100 Subject: [PATCH 11/14] bugfix --- git.functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git.functions b/git.functions index 8b4f85d..be4f206 100644 --- a/git.functions +++ b/git.functions @@ -103,7 +103,7 @@ git_hasRemote() local repositoryFolderPath="$1" local remoteName="$2" - git_inRepository "$repositoryFolderPath" remote | grep -q '^'"$remoteName"'$' + git_inRepository "$repositoryFolderPath" git remote | grep -q '^'"$remoteName"'$' } git_checkout() From 65abd7cede133b04a37d7f6258ad3c34e059b611 Mon Sep 17 00:00:00 2001 From: Raphael Cohn Date: Fri, 23 Oct 2015 15:45:06 +0100 Subject: [PATCH 12/14] Minor fix --- git.functions | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/git.functions b/git.functions index be4f206..41ada57 100644 --- a/git.functions +++ b/git.functions @@ -199,13 +199,14 @@ git_clean() pushd "$repositoryFolderPath" local submodule - while IFS= read -r submodule + local sha1 + while IFS= read -r submodule sha1 do if [ -n "$submodule" ]; then - git_clean "$submodule" HEAD + git_clean "$submodule" "$sha1" fi done <<-EOF - $(git submodule foreach -q 'echo "$path"') + $(git submodule foreach --quiet 'echo "$path" "$sha1"') EOF popd From c526c4ae1b9ac6d7d66ae70a4e30743c0585fab7 Mon Sep 17 00:00:00 2001 From: Raph Cohn Date: Tue, 27 Oct 2015 15:15:23 +0000 Subject: [PATCH 13/14] Clean --- git.functions | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/git.functions b/git.functions index 41ada57..d1879ad 100644 --- a/git.functions +++ b/git.functions @@ -188,6 +188,18 @@ git_commitToTagOrCommit() fi } +git_cleanIfGitPresent() +{ + local repositoryFolderPath="$1" + local repositoryCommit="$2" + + if core_compatibility_whichNoOutput git; then + if git_isPathSomewhereInsideGitRepository "$repositoryFolderPath"; then + git_clean "$repositoryFolderPath" "$repositoryCommit" + fi + fi +} + git_clean() { local repositoryFolderPath="$1" From 2c6536543df0655c74eb578cc16d75710ffc7621 Mon Sep 17 00:00:00 2001 From: Raph Cohn Date: Tue, 27 Oct 2015 15:16:49 +0000 Subject: [PATCH 14/14] LICENSE fix --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index c399ecd..dbf1bf6 100644 --- a/LICENSE +++ b/LICENSE @@ -1 +1 @@ -LICENSE terms are documented in the COPYRIGHT file at the top-level directory of this distribution and at https://raw.githubusercontent.com/shellfire-dev/jsonreader/master/COPYRIGHT. +LICENSE terms are documented in the COPYRIGHT file at the top-level directory of this distribution and at https://raw.githubusercontent.com/shellfire-dev/git/master/COPYRIGHT.