From a0f6cf9ea9fc0ca36263001a20bf1d0e00987731 Mon Sep 17 00:00:00 2001 From: vg Date: Sat, 23 Nov 2019 13:18:13 +0100 Subject: Rename git-sync to s/$/-noconflict/ Rename this command as their will be a new version failing in case of conflict instead of duplicating conflicting files. --- scripts/git-sync | 93 -------------------------------------------------------- 1 file changed, 93 deletions(-) delete mode 100755 scripts/git-sync (limited to 'scripts/git-sync') diff --git a/scripts/git-sync b/scripts/git-sync deleted file mode 100755 index e0117d7..0000000 --- a/scripts/git-sync +++ /dev/null @@ -1,93 +0,0 @@ -#!/bin/bash -set -eu - -verbose=0 -hosthash=$(python3 -c "import uuid, hashlib -print(hashlib.new('sha1', str(uuid.getnode()).encode('utf8')).hexdigest())") -#hostident="${HOSTNAME}" -hostident="${hosthash}" - -if [ -d "$(git rev-parse --git-dir)/annex" ]; then - echo 'Sync: using git annex' - exec git annex sync "$@" -fi - -# determine current branch name -branch_name=$(git symbolic-ref -q --short HEAD) - -# remote name -remote_name=$(git config --get branch.${branch_name}.remote || true) - -# conflict commit message -conflict_message="Merge conflict autocommit on ${hostident}" - -if [ -z "$remote_name" ]; then - echo "No remote for this repository" >&2 - exit 1 -fi - -if [ "$(git config --get --bool branch.${branch_name}.sync)" != "true" ]; then - echo "Branch is not configured to accept git-sync" >&2 - echo "To accept git-sync operation, set current branch sync to true:" >&2 - echo " git config --bool branch.${branch_name}.sync true" >&2 - exit 1 -fi - -if [ "$verbose" -ne 0 ]; then - echo 'Sync: git autocommit' -fi -git add -A "./$(git rev-parse --show-cdup)" -if ! git diff --cached --quiet; then - git status --short - git commit -m "Auto-commit on ${hostident}" -fi - -if [ "$verbose" -ne 0 ]; then - echo 'Sync: fetch and merge' -fi - -git fetch --quiet - -# might fail one time if conflict detected -git merge -m "$conflict_message" || true - -if [ "$verbose" -ne 0 ]; then - echo 'Sync: conflict autocommit' -fi - -git status --porcelain | while read -r filename; do - state="${filename:0:2}" - filename="${filename:3}" - ours="${filename}.${hostident}.conflict" - theirs="${filename}.${remote_name}.conflict" - case "$state" in - *U*) - git checkout --ours -- "$filename" - mv -i -- "$filename" "$ours" - git add -- "$ours" - git checkout --theirs -- "$filename" - cp -ai -- "$filename" "$theirs" - git add -- "$filename" - git add -- "$theirs" - ;; - esac -done - -# no action is done if there is nothing to commit -if git status --porcelain | grep -q .; then - git status --short - git commit -m "$conflict_message" -fi - -# should not fail again -git merge -m "$conflict_message" - -if [ "$verbose" -ne 0 ]; then - echo 'Sync: pushing changes' -fi - -git push --quiet - -if [ "$verbose" -ne 0 ]; then - echo 'Sync: done' -fi -- cgit v1.2.3 From afe5995276527606dc5ed731862a0891a9537a19 Mon Sep 17 00:00:00 2001 From: vg Date: Sat, 23 Nov 2019 13:19:45 +0100 Subject: new git-sync version failing in case of conflicts --- scripts/git-sync | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 scripts/git-sync (limited to 'scripts/git-sync') diff --git a/scripts/git-sync b/scripts/git-sync new file mode 100755 index 0000000..a9f07ac --- /dev/null +++ b/scripts/git-sync @@ -0,0 +1,27 @@ +#!/bin/bash +set -eu + +if [ -d "$(git rev-parse --git-dir)/annex" ]; then + echo 'Sync: using git annex' + exec git annex sync "$@" + exit 1 # if attained, this is an error +fi + +branch_name=$(git symbolic-ref -q --short HEAD) + +if [ "$(git config --get --bool branch.${branch_name}.sync)" != "true" ]; then + echo "Branch is not configured to accept git-sync, maybe you can do:" >&2 + echo " git config --bool branch.${branch_name}.sync true" >&2 + exit 1 +fi + +git fetch --all --quiet + +git add -A "./$(git rev-parse --show-cdup)" +if ! git diff --cached --quiet; then + git status --short + git commit -m "git-sync on ${HOSTNAME}" +fi + +git merge --ff-only +git push --quiet -- cgit v1.2.3 From 176e693e6861a46bb0a3581670380233203d5928 Mon Sep 17 00:00:00 2001 From: vg Date: Mon, 25 Nov 2019 07:34:31 +0100 Subject: update git-sync for simple merge cases Instead of using git merge --no-ff which always ensure no conflict, try to git merge covering simple cases (and automatically resolvable ones) at the cost of a merge commit but abort in case of conflicts needing manuable resolution. --- scripts/git-sync | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'scripts/git-sync') diff --git a/scripts/git-sync b/scripts/git-sync index a9f07ac..aa1facc 100755 --- a/scripts/git-sync +++ b/scripts/git-sync @@ -23,5 +23,10 @@ if ! git diff --cached --quiet; then git commit -m "git-sync on ${HOSTNAME}" fi -git merge --ff-only +#git merge --ff-only +if ! git merge --quiet --no-edit; then + git merge --abort + exit 1 +fi + git push --quiet -- cgit v1.2.3