-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgit-bundle-name
More file actions
executable file
·76 lines (70 loc) · 1.9 KB
/
Copy pathgit-bundle-name
File metadata and controls
executable file
·76 lines (70 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
# ---
# dateCreated: 2026-07-02
# relatedLink:
# - url: ../lib/shell-utilities/.disused/git-bundle-helper
# ...
NAME=git-bundle-name
VERSION=0.0.3
MODIFIED=2026-07-01
makeBundleName()
{
local shouldShowFullPath=false
local gitFirstArgs=() gitRevArgs=() commitTimestamp commitHashes repoName bundleName
while [[ $# -gt 0 ]]
do
case $1 in
-C) gitFirstArgs+=("$1" "$2"); shift;;
--full) shouldShowFullPath=true;;
*) gitRevArgs+=("$1");;
esac
shift
done
if [[ ${#gitRevArgs[@]} -eq 0 ]]
then
gitRevArgs+=(HEAD)
fi
commitTimestamp="$(git "${gitFirstArgs[@]}" log -n 1 --pretty='%at' "${gitRevArgs[@]}")" || return
commitHashes=($(git "${gitFirstArgs[@]}" rev-parse "${gitRevArgs[@]}")) || return
lastCommitHash="${commitHashes[@]:$((${#commitHashes[@]}-1))}" || return
repoPath="$(git "${gitFirstArgs[@]}" rev-parse --show-toplevel)" || return
repoName="$(basename "$repoPath")" || return
bundleName="${repoName}--${commitTimestamp}--${lastCommitHash}.bundle"
if [[ $shouldShowFullPath == true ]]
then
echo "$(dirname "$repoPath")/${bundleName}"
else
echo "$bundleName"
fi
}
showBundleNameHelp()
{
echo "SUMMARY: Generate a descriptive name for a git bundle file."
echo "USAGE: $NAME [-C PATH] [<git-rev-list-args>]"
echo
echo "OPTIONS:"
echo
echo $'\t'"-C PATH"
echo $'\t\t'"Reference git working copy at PATH, instead of PWD."
echo
echo $'\t'"--full"
echo $'\t\t'"Output the full path, putting the bundle alongside the working copy."
echo
echo $'\t'"-h, --help"
echo $'\t\t'"Show this help"
echo
echo $'\t'"<git-rev-list-args>"
echo $'\t\t'"See manual for git-bundle."
echo
echo "EXAMPLE:"
echo $'\t'"git bundle create \$(git-bundle-name --full) --all"
echo
echo "$NAME version $VERSION ($MODIFIED)"
}
for arg in "$@"
do
case $arg in
-h|--help) showBundleNameHelp; exit;;
esac
done
makeBundleName "$@"