88# - git-tarball-create: Creates a tarball based on a gitinclude (special gitginore) file
99# - git-repos: List all git repos (remote_url and git_dir)
1010
11+ git-tarball-create() {
12+
13+ # git-tarball-create - Creates a tarball based on a single gitinclude file
14+ #
15+ # Usage: git-tarball-create <gitinclude_file>
16+ #
17+
18+ local gitinclude_file="${1:-}"
19+
20+ # Verify gitinclude_file argument is provided
21+ if [[ -z $gitinclude_file ]]; then
22+ echo "Usage: tarball-create <gitinclude_file>" >&2
23+ return 1
24+ elif [[ ! -f $gitinclude_file ]]; then
25+ # Verify gitinclude_file file exists
26+ echo "Error: gitinclude file '$gitinclude_file' not found." >&2
27+ return 1
28+ fi
29+
30+ local last_commit_date="$(git log -1 --format=%cd --date=format:%Y-%m-%d)"
31+ local git_repo_path="$(git rev-parse --show-toplevel)"
32+ local git_repo_name="${git_repo_path##*/}"
33+ local variant="$(basename "${gitinclude_file}")"
34+ local release="${git_repo_name}-${variant}-${last_commit_date}"
35+ local build_dir="${git_repo_path}/build"
36+ local tarball="${build_dir}/${release}.tar.gz"
37+
38+ (
39+ cd "${git_repo_path}" || exit
40+ # Ensure the build directory exists
41+ mkdir -p "$build_dir" || { echo "Failed to create build directory: $build_dir" >&2; return 1; }
42+
43+ # Use git to list files for inclusion in the tarball
44+ if ! git-ls-noticed "$gitinclude_file" \
45+ | tar \
46+ --transform "s,^,${release}/," \
47+ --transform 's,${release}/\([^/]*\) -> \(.*\),\1 -> \2,' \
48+ -czf "${tarball}" -T -
49+ then
50+ echo "Error: Failed to create tarball." >&2
51+ return 1
52+ fi
53+ )
54+
55+ echo "Tarball created: ${tarball}"
56+ }
57+
58+ git-archive() {
59+
60+ local last_commit_date="$(git log -1 --format=%cd --date=format:%Y-%m-%d)"
61+ local git_repo_path="$(git rev-parse --show-toplevel)"
62+ local git_repo_name="${git_repo_path##*/}"
63+ local release="${git_repo_name}-${last_commit_date}"
64+ local build_dir="${git_repo_path}/build"
65+ local tarball="${build_dir}/${release}.tar.gz"
66+ local label="$(basename $(git rev-parse --show-toplevel))-$(git log -1 --format=%cd --date=format:%Y-%m-%d)"
67+
68+ (
69+ cd "${git_repo_path}" || exit
70+
71+ # Ensure the build directory exists
72+ mkdir -p "$build_dir" || { echo "Failed to create build directory: $build_dir" >&2; return 1; }
73+
74+ git archive \
75+ --prefix="${release}/" \
76+ --format=tar.gz \
77+ -o "${build_dir}/${release}.tar.gz" \
78+ HEAD
79+ )
80+ }
81+
82+ git-remote-add-github() {
83+ git remote add github "github.com_mbailey:mbailey/$(git-repo-name).git"
84+ git branch -M master
85+ git push -u github master
86+ }
87+
88+ git-repo-name() {
89+ basename "$(git rev-parse --show-toplevel)"
90+ }
91+
1192git-repos() {
1293
13- local search_dir="${1:-.}" # Use provided directory or default to current directory if not provided
14-
15- # Find all .git directories under the specified directory
16- find "$search_dir" -type d -name .git 2>/dev/null | while read -r git_dir; do
17- local repo_dir
18- repo_dir=$(dirname "$git_dir") # Get the repository directory by removing the .git part
19- local repo_url
20- repo_url=$(git -C "$repo_dir" config --get remote.origin.url) # Get the repository's remote URL
21- printf "%s\t%s\n" "$repo_url" "${repo_dir}" # Print the repository URL and directory path, separated by a tab
22- done \
23- | sort -k1,1 \
24- | bma columnise
94+ local search_dirs="$(skim-stdin "$@")"
95+ [[ -z $search_dirs ]] && search_dirs='.'
96+
97+ # debug "$search_dirs"
98+
99+ # Find all .git directories under the specified directories
100+ for search_dir in $search_dirs; do
101+ find -L "$search_dir" -type d -name .git 2>/dev/null | while read -r git_dir; do
102+ local repo_dir
103+ repo_dir=$(dirname "$git_dir") # Get the repository directory by removing the .git part
104+ local repo_url
105+ repo_url=$(git -C "$repo_dir" config --get remote.origin.url) # Get the repository's remote URL
106+ printf "%s\t%s\n" "$repo_url" "${repo_dir}" # Print the repository URL and directory path, separated by a tab
107+ done \
108+ | sort -k1,1 \
109+ | bma columnise
110+ done
25111}
26112
27113git-ls-noticed() {
@@ -36,6 +122,10 @@ git-ls-noticed() {
36122 # `--ignored`: Lists all files that are ignored by git
37123 # `--cached`: Lists all files that are staged for commit. (Required to use `--ignored`.)
38124 # `--exclude-from`: Use specified file as the ignore file (and ignore all others)
125+ #
126+ # Test with:
127+ #
128+ # diff <(git-ls-noticed path/to/.gitinclude/target) <(tar-ls build/example-target-2024-04-17.tar.gz)
39129
40130 local gitinclude_file="${1:-}"
41131
@@ -65,49 +155,6 @@ git-ls-noticed() {
65155 )
66156}
67157
68- git-tarball-create() {
69-
70- # git-tarball-create - Creates a tarball based on a single gitinclude file
71- #
72- # Usage: git-tarball-create <gitinclude_file>
73- #
74-
75- local gitinclude_file="${1:-}"
76-
77- # Verify gitinclude_file argument is provided
78- if [[ -z $gitinclude_file ]]; then
79- echo "Usage: tarball-create <gitinclude_file>" >&2
80- return 1
81- elif [[ ! -f $gitinclude_file ]]; then
82- # Verify gitinclude_file file exists
83- echo "Error: gitinclude file '$gitinclude_file' not found." >&2
84- return 1
85- fi
86-
87- local last_commit_date="$(git log -1 --format=%cd --date=format:%Y-%m-%d)"
88- local git_repo_path="$(git rev-parse --show-toplevel)"
89- local git_repo_name="${git_repo_path##*/}"
90- local variant="$(basename "${gitinclude_file}")"
91- local release="${git_repo_name}-${variant}-${last_commit_date}"
92- local build_dir="build"
93- local tarball="${build_dir}/${release}.tar.gz"
94-
95- (
96- cd "${git_repo_path}" || exit
97- # Ensure the build directory exists
98- mkdir -p "$build_dir" || { echo "Failed to create build directory: $build_dir" >&2; return 1; }
99-
100- # Use git to list files for inclusion in the tarball
101- if ! git-ls-noticed "$gitinclude_file" \
102- | tar --transform "s,^,${release}/," -czf "${tarball}" -T -
103- then
104- echo "Error: Failed to create tarball." >&2
105- return 1
106- fi
107- )
108-
109- echo "Tarball created: ${tarball}"
110- }
111158
112159
113160git-repo-dirs(){
0 commit comments