aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cheatsheet.txt38
-rwxr-xr-xforeach-git64
-rwxr-xr-xserver/mkrepo2
-rwxr-xr-xserver/mrrepo71
4 files changed, 141 insertions, 34 deletions
diff --git a/cheatsheet.txt b/cheatsheet.txt
index 4413252..42655a1 100644
--- a/cheatsheet.txt
+++ b/cheatsheet.txt
@@ -1,20 +1,44 @@
Global Setup
- See also Submodules below.
+ See also Submodules and History Cleanup configurations below.
+
+ git config --global user.name "First Last"
+ git config --global user.email first@example.com
git config --global color.status.branch magenta
- # This makes sure that changes to tags are also fetched.
+ # This makes sure that changes to tags are also fetched. The second
+ # version in addition makes sure they are overriden (required from
+ # git 2.20.0).
#
git config --global remote.origin.tagopt --tags
+ git config --global remote.origin.fetch '+refs/tags/*:refs/tags/*'
+ git config --global --unset remote.origin.tagopt
- # Starting 2.20 the above doesn't work anymore and should be replaced:
+ # Enable hooks globally.
#
- git config --global remote.origin.fetch "+refs/tags/*:refs/tags/*"
- git config --global --unset remote.origin.tagopt
+ git config --global core.hooksPath <bdep-util-project-dir>/bdep-util/git-hooks
+ # Override the global hooks with the repository-specific hooks (run in a
+ # repository directory).
+ #
+ git config core.hooksPath .git/hooks
+
+Commit Messages
+
+1. Separate subject from body with a blank line
+2. Limit the subject line to 78 characters
+3. Capitalize the subject line
+4. Do not end the subject line with a period
+5. Use the imperative voice in the subject line (e.g., "Implement foo" rather
+ than "Implemented foo")
+6. No articles (a/the) in the subject line
+7. Wrap the body at 78 characters
+8. Unless this is already captured in the commit payload (e.g., in
+ code comments, documentation, etc) use the body to explain what
+ and why
Undo (move to index) last commit
@@ -109,7 +133,9 @@ History Cleanup
that usually the result of the git merge command.
Note: make sure you have rerere enabled for this process to work
- smoothly (~/.gitconfig).
+ smoothly:
+
+ git config --global rerere.enabled true
Note: if you are just learning this procedure, make a local backup
copy of your repository in case things go badly and you need to
diff --git a/foreach-git b/foreach-git
new file mode 100755
index 0000000..9ad529f
--- /dev/null
+++ b/foreach-git
@@ -0,0 +1,64 @@
+#! /usr/bin/env bash
+
+# Run git command in each directory that looks like a git repository. By
+# default only top-level directoris are considered but the depth can be
+# adjusted with -d.
+#
+# -x <dir>
+# Exclude <dir>.
+#
+# -n <num>
+# Directory depth to consider.
+#
+#
+
+trap "{ exit 1; }" ERR
+set -o errtrace # Trap in functions.
+
+function info () { echo "$*" 1>&2; }
+
+exclude=() # Array of excluded directories.
+depth=1
+
+while [ $# -gt 0 ]; do
+ case $1 in
+ -x)
+ shift
+ exclude+=("${1%/}")
+ shift
+ ;;
+ -n)
+ shift
+ depth="$1"
+ shift
+ ;;
+ *)
+ break
+ ;;
+ esac
+done
+
+# Find all the top-level directories that looks like git repositories.
+#
+dirs=()
+for d in $(find . -mindepth 1 -maxdepth "$depth" -type d -printf '%P\n' | sort); do
+ if [ -d "$d/.git" ]; then
+ dirs+=("$d")
+ fi
+done
+
+# Run the command for each of them.
+#
+for d in "${dirs[@]}"; do
+ for e in "${exclude[@]}"; do
+ if [[ "$d/" =~ ^"$e/" ]]; then
+ d=
+ break
+ fi
+ done
+
+ if [ -n "$d" ]; then
+ info "$d/"
+ git -C "$d" "${@}"
+ fi
+done
diff --git a/server/mkrepo b/server/mkrepo
index f89324e..32cb0b8 100755
--- a/server/mkrepo
+++ b/server/mkrepo
@@ -62,7 +62,7 @@ gr='scm'
mkdir -p "$r"
chgrp "$gr" "$r"
git --bare init --shared=all "$r"
-info "Enter project description (one line; or edit $r/descrition later)"
+info "Enter project description (one line; or edit $r/description later)"
info "Hit Ctrl-D when done"
cat >"$r/description"
chgrp -R "$gr" "$r"
diff --git a/server/mrrepo b/server/mrrepo
index 1bb3989..469a03f 100755
--- a/server/mrrepo
+++ b/server/mrrepo
@@ -40,7 +40,7 @@
#
# runuser -u scm -- /var/scm/mrrepo -s -v git.example.org /var/scm
#
-usage="usage: $0 [-v] [-s] <host> <path>"
+usage="usage: $0 [-v] [-s] [<host>] <path>"
owd="$(pwd)"
trap "{ cd '$owd'; exit 1; }" ERR
@@ -65,19 +65,34 @@ while [ "$#" -gt 0 ]; do
shift
;;
*)
- if [ -z "$host" ]; then
- host="$1"
- elif [ -z "$path" ]; then
- path="${1%/}"
- else
- error "$usage"
- fi
- shift
+ break; # The end of options is encountered.
;;
esac
done
-if [ -z "$host" -o -z "$path" ]; then
+# Parse the command line arguments.
+#
+if [ "$#" -lt 1 -o "$#" -gt 2 ]; then
+ error "$usage"
+fi
+
+# Host.
+#
+if [ "$#" -gt 1 ]; then
+ host="$1"
+ shift
+
+ if [ -z "$host" ]; then
+ error "$usage"
+ fi
+fi
+
+# Repositories directory.
+#
+path="${1%/}"
+shift
+
+if [ -z "$path" ]; then
error "$usage"
fi
@@ -121,8 +136,6 @@ function fetch () # <url> [<curl-options>]
curl "${curl_ops[@]}" "$@" "$u"
}
-fetch "$prot://$host/manifest" -z remote.manifest -o remote.manifest
-
function manifest_filter () # <file>
{
sed -e '/^\s*#/d;/^\s*$/d;s/\s\s*/ /g' "$1"
@@ -169,18 +182,22 @@ function push_add () # <rep> <url>
push_auth["$r"]="$u"
}
-while read l || [ -n "$l" ]; do
- r=$(manifest_field "$l" 1 'path')
- u=$(manifest_field "$l" 2)
+if [ -n "$host" ]; then
+ fetch "$prot://$host/manifest" -z remote.manifest -o remote.manifest
- remote+=("$r")
+ while read l || [ -n "$l" ]; do
+ r=$(manifest_field "$l" 1 'path')
+ u=$(manifest_field "$l" 2)
- # If the push URL is specified then add it to auth/orig maps.
- #
- if [ -n "$u" ]; then
- push_add "$r" "$u"
- fi
-done < <(manifest_filter remote.manifest)
+ remote+=("$r")
+
+ # If the push URL is specified then add it to auth/orig maps.
+ #
+ if [ -n "$u" ]; then
+ push_add "$r" "$u"
+ fi
+ done < <(manifest_filter remote.manifest)
+fi
# Find all the existing repositories (directories that end with .git) and sort
# them out into mirrored and local public. Note that local private will end up
@@ -202,7 +219,7 @@ if test -f manifest; then
for i in "${remote[@]}"; do
if [ "$i" = "$r" ]; then
- error "attempt to mirror into local public repository $r"
+ error "attempt to mirror into local public repository $r"
fi
done
@@ -222,10 +239,10 @@ if test -f manifest; then
for i in "${local[@]}"; do
if [ "$i" = "$r" ]; then
if [ "$verb" -ge 1 ]; then
- info "local public repository $r"
- fi
- r=
- break
+ info "local public repository $r"
+ fi
+ r=
+ break
fi
done