From d501c45da1d52dd59e50c99f672eb18213ba4031 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Tue, 20 Aug 2024 16:31:35 +0300 Subject: [PATCH 01/16] Feat(update-remotes): Get additional files to sync from `.git/config` --- update-remotes | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/update-remotes b/update-remotes index 5211f9b..cf09215 100755 --- a/update-remotes +++ b/update-remotes @@ -6,13 +6,14 @@ origin="`git config --get --path remote.origin.url`" || : web="`git config --get --path remote.web.url`" || : remotes="`git config --get update-remotes.remotes`" || : branches="`git config --get update-remotes.branches`" || : +files="`git config --get update-remotes.files`" || : if [ -n "$origin" ]; then if [ -n "$current" ]; then echo "Config error (both origin and current)" >&2 exit 1 else - rsync -ahPv update-remotes "$origin" + rsync -ahPv $files update-remotes "$origin" cd "$origin" exec ./update-remotes fi -- 2.39.5 From 873d40b7d112962e4675268c5f3454d6a615c285 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Wed, 4 Sep 2024 21:25:52 +0300 Subject: [PATCH 02/16] Fix(delete): Fix `cmp` command line --- delete | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/delete b/delete index 6002dc4..eacf01d 100755 --- a/delete +++ b/delete @@ -21,7 +21,7 @@ rm -rf "$path_to_repo" && tmpfile="`mktemp`" && grep -v "^$path_to_repo\$" locate-all.list > "$tmpfile" && -if cmp -s mv "$tmpfile" locate-all.list; then +if cmp -s "$tmpfile" locate-all.list; then exec rm -f "$tmpfile" else exec mv "$tmpfile" locate-all.list -- 2.39.5 From acdea47d7f5d3ab1a3e24a97e5317f09be134560 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Thu, 5 Sep 2024 18:38:59 +0300 Subject: [PATCH 03/16] Fix(update-remotes): Fetch named branches --- update-remotes | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/update-remotes b/update-remotes index cf09215..05ce939 100755 --- a/update-remotes +++ b/update-remotes @@ -22,7 +22,7 @@ elif [ -z "$current" ]; then exit 1 fi -git fetch current +git fetch current master $branches { git pull --ff-only current master || git reset --hard current/master ; } git set-date -- 2.39.5 From 17122f33d0011656e73440bb88ded051ad2feed1 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Sat, 7 Sep 2024 13:31:26 +0300 Subject: [PATCH 04/16] Feat(update-remotes): Use `git config --get-all` Use `git config --add` to add to the list. This allows to add/remove without copying the entire list. --- update-remotes | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/update-remotes b/update-remotes index 05ce939..5237db9 100755 --- a/update-remotes +++ b/update-remotes @@ -5,8 +5,8 @@ current="`git config --get --path remote.current.url`" || : origin="`git config --get --path remote.origin.url`" || : web="`git config --get --path remote.web.url`" || : remotes="`git config --get update-remotes.remotes`" || : -branches="`git config --get update-remotes.branches`" || : -files="`git config --get update-remotes.files`" || : +branches="`git config --get-all update-remotes.branches`" || : +files="`git config --get-all update-remotes.files`" || : if [ -n "$origin" ]; then if [ -n "$current" ]; then -- 2.39.5 From c6af4d8f974b605bc83c722510f4f87c41c0a05f Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Sun, 17 Nov 2024 00:32:36 +0300 Subject: [PATCH 05/16] Refactor(submodules/remove): Get `GIT_DIR` once Call `git rev-parse --git-dir` once. Also replace `$()` with backticks. --- submodules/remove | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/submodules/remove b/submodules/remove index f9436ce..4906a0b 100755 --- a/submodules/remove +++ b/submodules/remove @@ -18,7 +18,7 @@ if [ \! -f .gitmodules ]; then fi name="$1" -path="$(git config -f .gitmodules --get "submodule.$name.path")" +path="`git config -f .gitmodules --get "submodule.$name.path"`" if [ -z "$path" ]; then echo "Error: submodule $name does not exist" >&2 @@ -26,13 +26,14 @@ if [ -z "$path" ]; then fi git rm $cached "$path" && -rm -rf "`git rev-parse --git-dir`"/modules/"$name" && +GIT_DIR=`git rev-parse --git-dir` && +rm -rf "$GIT_DIR"/modules/"$name" && git config --remove-section submodule."$name" && if [ \! -s .gitmodules ]; then git rm -f .gitmodules fi && -if [ -z $(ls -A "`git rev-parse --git-dir`/modules") ]; then - exec rmdir "`git rev-parse --git-dir`/modules" +if [ -z `ls -A "$GIT_DIR/modules"` ]; then + exec rmdir "$GIT_DIR/modules" fi -- 2.39.5 From 8b6d45e333658969b4c40f51f0b252822cf69250 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Mon, 18 Nov 2024 12:41:29 +0300 Subject: [PATCH 06/16] Fix(submodules/remove): Add external quotes --- submodules/remove | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/submodules/remove b/submodules/remove index 4906a0b..d66ef34 100755 --- a/submodules/remove +++ b/submodules/remove @@ -34,6 +34,6 @@ if [ \! -s .gitmodules ]; then git rm -f .gitmodules fi && -if [ -z `ls -A "$GIT_DIR/modules"` ]; then +if [ -z "`ls -A \"$GIT_DIR/modules\"`" ]; then exec rmdir "$GIT_DIR/modules" fi -- 2.39.5 From 569bef72896a2d8ba6bccd4b1017ded232c9b4c9 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Mon, 6 Jan 2025 03:55:08 +0300 Subject: [PATCH 07/16] Stop running `chmod a-x .git/config`, Git no longer requires it --- clone | 4 +--- fix-config | 4 ---- fix-config-recursive | 4 ---- fix-config-repos | 7 ------- fork | 1 - 5 files changed, 1 insertion(+), 19 deletions(-) delete mode 100755 fix-config delete mode 100755 fix-config-recursive delete mode 100755 fix-config-repos diff --git a/clone b/clone index 5d1118d..58d898c 100755 --- a/clone +++ b/clone @@ -16,9 +16,7 @@ fi && if [ -d .git ]; then git remote set-url origin "$origin" else - git clone -o origin "$origin" "$local_repo" && - cd "$local_repo" && - chmod a-x .git/config + git clone -o origin "$origin" "$local_repo" fi && "`dirname \"$0\"`"/set-commit-date-recursive && diff --git a/fix-config b/fix-config deleted file mode 100755 index f7d4cda..0000000 --- a/fix-config +++ /dev/null @@ -1,4 +0,0 @@ -#! /bin/sh - -g="`git rev-parse --git-dir`" && -exec chmod a-x "$g"/config diff --git a/fix-config-recursive b/fix-config-recursive deleted file mode 100755 index afbe197..0000000 --- a/fix-config-recursive +++ /dev/null @@ -1,4 +0,0 @@ -#! /bin/sh - -prog_dir="`dirname \"$0\"`" && -exec "$prog_dir"/run-recursive "$prog_dir"/fix-config diff --git a/fix-config-repos b/fix-config-repos deleted file mode 100755 index da5e46e..0000000 --- a/fix-config-repos +++ /dev/null @@ -1,7 +0,0 @@ -#! /bin/sh - -cd "`dirname \"$0\"`" && -prog_dir="`pwd`" && -export prog_dir - -exec "$prog_dir"/run-repos "$prog_dir"/fix-config-recursive diff --git a/fork b/fork index 5188356..cbf5d9a 100755 --- a/fork +++ b/fork @@ -20,7 +20,6 @@ if [ -d .git ]; then else git clone -o upstream "$upstream" "$local_repo" && cd "$local_repo" && - chmod a-x .git/config && git remote add origin "$origin" fi && -- 2.39.5 From 01bf09c816e0119d8d4264c9ee1ab70611a16450 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Mon, 6 Jan 2025 04:10:07 +0300 Subject: [PATCH 08/16] Add `fix-permissions-repos` --- fix-permissions-repos | 15 +++++++++++++++ pull-usrlocalsrc | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100755 fix-permissions-repos diff --git a/fix-permissions-repos b/fix-permissions-repos new file mode 100755 index 0000000..b8e01ca --- /dev/null +++ b/fix-permissions-repos @@ -0,0 +1,15 @@ +#! /bin/sh + +prog_dir="`dirname \"$0\"`" && + +cat "$prog_dir"/locate-all.list | + grep -v "^$HOME/Internet/WWW/htdocs/git.phdru.name/" | +while read d; do + echo "----- $d -----"; cd "$d" && + if test -d "$d/.git"; then cd "$d/.git"; fi && # bare repo + chmod -R u=rwX,go= . && + find objects -type f -exec chmod u=r,go= '{}' \+ +done && + +cd "$HOME/Internet/WWW/htdocs/git.phdru.name/" && +pwd && exec chmod -R u=rwX,go=rX . diff --git a/pull-usrlocalsrc b/pull-usrlocalsrc index c7159ad..4b524d7 100755 --- a/pull-usrlocalsrc +++ b/pull-usrlocalsrc @@ -6,7 +6,7 @@ has_remote() { prog_dir="`dirname \"$0\"`" && -cat "$prog_dir"/locate-all.list | grep -F /usr/local/src | +cat "$prog_dir"/locate-all.list | grep "^/usr/local/src/" | while read d; do echo "----- $d -----"; cd "$d" && if has_remote upstream && has_remote origin; then -- 2.39.5 From 91f4e4d5ca15f1ff80cc0f17b2bd4474a753c403 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Thu, 9 Jan 2025 14:44:06 +0300 Subject: [PATCH 09/16] Refactor: `git show --format=` -> `git show --pretty=format:` --- hooks/post-checkout/set-last-commit-date-all | 2 +- hooks/post-checkout/set-last-commit-date-changed | 2 +- hooks/post-checkout/set-last-commit-date-committed | 2 +- set-commit-date | 2 +- set-commit-date.py | 3 ++- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/hooks/post-checkout/set-last-commit-date-all b/hooks/post-checkout/set-last-commit-date-all index 1c87fba..4cceb0f 100755 --- a/hooks/post-checkout/set-last-commit-date-all +++ b/hooks/post-checkout/set-last-commit-date-all @@ -8,7 +8,7 @@ new_HEAD="$2" new_branch="$3" if [ "$new_branch" = 1 ]; then - commit_date="`git show --format='%cD' -s`" && + commit_date="`git show --pretty=tformat:'%cD' -s`" && find . \( -name .git -type d -prune \) -o \ -exec touch --date="$commit_date" '{}' \+ fi diff --git a/hooks/post-checkout/set-last-commit-date-changed b/hooks/post-checkout/set-last-commit-date-changed index 1a6b0ac..267711e 100755 --- a/hooks/post-checkout/set-last-commit-date-changed +++ b/hooks/post-checkout/set-last-commit-date-changed @@ -8,7 +8,7 @@ new_HEAD="$2" new_branch="$3" if [ "$new_branch" = 1 ]; then - commit_date="`git show --format='%cD' -s`" && + commit_date="`git show --pretty=tformat:'%cD' -s`" && touch --date="$commit_date" `git diff --name-only HEAD~` fi diff --git a/hooks/post-checkout/set-last-commit-date-committed b/hooks/post-checkout/set-last-commit-date-committed index 1e88974..f55ea77 100755 --- a/hooks/post-checkout/set-last-commit-date-committed +++ b/hooks/post-checkout/set-last-commit-date-committed @@ -8,7 +8,7 @@ new_HEAD="$2" new_branch="$3" if [ "$new_branch" = 1 ]; then - commit_date="`git show --format='%cD' -s`" && + commit_date="`git show --pretty=tformat:'%cD' -s`" && touch --date="$commit_date" `git ls-files --cached` fi diff --git a/set-commit-date b/set-commit-date index fcc7539..db48c59 100755 --- a/set-commit-date +++ b/set-commit-date @@ -4,5 +4,5 @@ # and set the file's modification time to that date/time. git ls-tree -r --name-only HEAD | while read filename; do - touch --date="`git log -1 --format=\"%cD\" -- \"$filename\"`" "$filename" + touch --date="`git log -1 --pretty=tformat:\"%cD\" -- \"$filename\"`" "$filename" done diff --git a/set-commit-date.py b/set-commit-date.py index c0aaa8c..67d2c4f 100755 --- a/set-commit-date.py +++ b/set-commit-date.py @@ -34,7 +34,8 @@ separator = '----- GIT LOG SEPARATOR -----' git_log = subprocess.Popen(['git', 'log', '-m', '--first-parent', '--name-status', '--no-color', - '--format=%s%%n%%%st' % (separator, date_format)], + '--pretty=tformat:%s%%n%%%st' % ( + separator, date_format)], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True) changed_files = set() -- 2.39.5 From d0376cf544046b41edccdafdedadd87679b9eed2 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Sun, 12 Jan 2025 00:48:49 +0300 Subject: [PATCH 10/16] Feat(fork): Set URL for `upstream` --- fork | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fork b/fork index cbf5d9a..7238ada 100755 --- a/fork +++ b/fork @@ -15,8 +15,10 @@ if [ -d "$local_repo"/.git ]; then fi && if [ -d .git ]; then - git remote add upstream "$upstream" - git remote set-url origin "$origin" || git remote add origin "$origin" + git remote add upstream "$upstream" || + git remote set-url upstream "$upstream" + git remote set-url origin "$origin" || + git remote add origin "$origin" else git clone -o upstream "$upstream" "$local_repo" && cd "$local_repo" && -- 2.39.5 From 210a9cb6184c644d06be9aa8925d4a13e0c0403b Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Sat, 18 Jan 2025 14:05:26 +0300 Subject: [PATCH 11/16] Feat(git-current-branch): List local branches for `HEAD` List local branches from which `HEAD` is reachable. --- git-current-branch | 1 + 1 file changed, 1 insertion(+) diff --git a/git-current-branch b/git-current-branch index 19cedf4..d485dea 100755 --- a/git-current-branch +++ b/git-current-branch @@ -4,6 +4,7 @@ git branch --show-current git describe --all +git for-each-ref --contains=HEAD --format="%(refname)" refs/heads/ git name-rev --name-only HEAD git rev-parse --abbrev-ref HEAD -- 2.39.5 From dbab6b2c0d54def3b6100e24abce22631d893014 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Wed, 19 Feb 2025 14:26:58 +0300 Subject: [PATCH 12/16] Fix(delete): Fix arguments count --- delete | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/delete b/delete index eacf01d..1a4bc1e 100755 --- a/delete +++ b/delete @@ -1,6 +1,6 @@ #! /bin/sh -if [ -z "$1" -o -n "$3" ]; then +if [ -z "$1" -o -n "$2" ]; then echo "Usage: $0 /path/to/repo" >&2 exit 1 fi -- 2.39.5 From e2a759b7ba009f6d095524b64634eb47aa87b206 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Thu, 20 Mar 2025 11:37:03 +0300 Subject: [PATCH 13/16] Add script `init` The primary goal is to automatically add the new repository to `locate-all.list`. --- init | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100755 init diff --git a/init b/init new file mode 100755 index 0000000..849ba89 --- /dev/null +++ b/init @@ -0,0 +1,17 @@ +#! /bin/sh + +if [ -n "$2" ]; then + echo "Usage: $0 [subdir]" >&2 + exit 1 +fi + +set -e +subdir="$1" + +if [ -n "$subdir" ]; then + mkdir -p "$subdir" + cd "$subdir" +fi + +git init +pwd >> "`dirname \"$0\"`"/locate-all.list -- 2.39.5 From d39c494cdaeeafee05e88d0e52bc071b910ad8d4 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Sat, 19 Apr 2025 00:44:34 +0300 Subject: [PATCH 14/16] Feat: Edit `.git/description` after clone --- clone | 3 ++- copy-scripts/copy-scripts | 19 +++++++++++++++---- fork | 1 + 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/clone b/clone index 58d898c..774d6a7 100755 --- a/clone +++ b/clone @@ -21,7 +21,8 @@ fi && "`dirname \"$0\"`"/set-commit-date-recursive && pwd >> "`dirname \"$0\"`"/locate-all.list && -branch="`git rev-parse --abbrev-ref HEAD`" +branch="`git rev-parse --abbrev-ref HEAD`" && +`git var GIT_EDITOR` .git/description && git config push.default current && exec git gc --aggressive diff --git a/copy-scripts/copy-scripts b/copy-scripts/copy-scripts index 2201c0f..83f2d47 100755 --- a/copy-scripts/copy-scripts +++ b/copy-scripts/copy-scripts @@ -12,9 +12,20 @@ remote_host="$1" remote_dir="$2" remote_name="$3" -ssh "$remote_host" "cd $remote_dir && exec git init --bare git-scripts.git" && +ssh "$remote_host" " + cd $remote_dir && + git init --bare git-scripts.git + cd git-scripts.git && + echo Small git scripts >.git/description +" && + git remote add "$remote_name" "$remote_host:$remote_dir/git-scripts.git" && git push "$remote_name" master && -exec ssh "$remote_host" "cd $remote_dir && git clone git-scripts.git && - cd git-scripts.git/hooks && - exec ln -s ../../git-scripts/copy-scripts/post-update" + +exec ssh "$remote_host" " + cd $remote_dir && + git clone git-scripts.git && + cd git-scripts && + echo Small git scripts >.git/description && + cd ../git-scripts.git/hooks && + exec ln -s ../../git-scripts/copy-scripts/post-update" diff --git a/fork b/fork index 7238ada..348c5e6 100755 --- a/fork +++ b/fork @@ -38,4 +38,5 @@ git config branch.$branch.remotepush origin && git config branch.$branch.merge refs/heads/$branch && git config push.default current && +`git var GIT_EDITOR` .git/description && exec git gc --aggressive -- 2.39.5 From bf2bc83b707028576055be7a89249d5b38c92023 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Tue, 29 Apr 2025 15:42:46 +0300 Subject: [PATCH 15/16] Docs(README): I removed `clone2current` and `publish2web` long ago Actually I moved them to a different repository. --- README.txt | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/README.txt b/README.txt index 3fb6557..24ff47a 100644 --- a/README.txt +++ b/README.txt @@ -2,13 +2,3 @@ git scripts =========== Small scripts I use. Public domain. - -svn/ - scripts for converting a Subversion repository to git using git-svn. -See svn/README.txt. - -clone2current - clone a repository to ~/current/projects; add remote "current" -to the original repository to pull updates from. - -publish2web - clone a repository to ~/Internet/WWW/htdocs/git.phdru.name from -where it will be copied to git.phdru.name web site; add remote "web" -to the original repository to push updates. -- 2.39.5 From 68162fbd7153af283afe54a93efcfea45189b5fd Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Tue, 29 Apr 2025 15:44:44 +0300 Subject: [PATCH 16/16] Refactor: Edit `.git/description` as the last step --- clone | 4 ++-- fork | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/clone b/clone index 774d6a7..0d2a1fc 100755 --- a/clone +++ b/clone @@ -23,6 +23,6 @@ fi && pwd >> "`dirname \"$0\"`"/locate-all.list && branch="`git rev-parse --abbrev-ref HEAD`" && -`git var GIT_EDITOR` .git/description && git config push.default current && -exec git gc --aggressive +git gc --aggressive && +exec `git var GIT_EDITOR` .git/description diff --git a/fork b/fork index 348c5e6..6c07d6c 100755 --- a/fork +++ b/fork @@ -38,5 +38,5 @@ git config branch.$branch.remotepush origin && git config branch.$branch.merge refs/heads/$branch && git config push.default current && -`git var GIT_EDITOR` .git/description && -exec git gc --aggressive +git gc --aggressive && +exec `git var GIT_EDITOR` .git/description -- 2.39.5