From 86871ef2fc32647099147f9c767d365019d35644 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Wed, 15 Feb 2017 04:36:39 -0800 Subject: [PATCH] tg-create.sh: remove mention of --continue The `tg create` comand doesn't have its own `--continue` operation anymore, it just runs `tg update` under-the-hood as the last step and so makes use of the `tg update --continue` command instead when necessary. Remove all mention of and related logic for the `tg create [--continue]` command to reflect this. Also make sure that "@" is understood as "HEAD" where appropriate. Signed-off-by: Kyle J. McKay --- README | 13 ++-- tg-create.sh | 200 +++++++++++++++++++++++------------------------------------ tg.sh | 3 - 3 files changed, 84 insertions(+), 132 deletions(-) diff --git a/README b/README index 6b1a242..9ff6852 100644 --- a/README +++ b/README @@ -147,14 +147,13 @@ SYNOPSIS tg: Creating t/whatever base from t/revlist/author-fixed... tg: Merging t/whatever base with t/gitweb/nifty-links... Merge failed! - tg: Please commit merge resolution and call: tg create --continue + tg: Please commit merge resolution and call: tg update --continue tg: It is also safe to abort this operation using `git reset --hard` tg: but please remember you are on the base branch now; tg: you will want to switch to a different branch. $ ..resolve.. $ git commit - $ tg create --continue - tg: Resuming t/whatever setup... + $ tg update --continue $ ..hack.. $ git commit @@ -559,11 +558,9 @@ tg create The main task of ``tg create`` is to set up the topic branch base from the dependencies. This may fail due to merge conflicts if more - than one dependencie is given. In that case, after you commit the - conflict resolution, you should call ``tg create`` again (without any - arguments or with the single argument ``--continue``); it will then - detect that you are on a topic branch base ref and resume the topic - branch creation operation. + than one dependency is given. In that case, after you commit the + conflict resolution, you should call ``tg update --continue`` to + finish merging the dependencies into the new topic branch base. With the ``--no-deps`` option at most one dependency may be listed which may be any valid committish (instead of just refs/heads/...) and diff --git a/tg-create.sh b/tg-create.sh index e0bb480..35f5533 100644 --- a/tg-create.sh +++ b/tg-create.sh @@ -1,12 +1,11 @@ #!/bin/sh # TopGit - A different patch queue manager # Copyright (C) Petr Baudis 2008 -# Copyright (C) Kyle J. McKay 2015 +# Copyright (C) Kyle J. McKay 2015,2016,2017 # All rights reserved. # GPLv2 deps= # List of dependent branches -restarted= # Set to 1 if we are picking up in the middle of base setup merge= # List of branches to be merged; subset of $deps name= rname= # Remote branch to base this one on @@ -19,7 +18,6 @@ topmsgfile= noedit= nocommit= nodeps= -continue= topmsg= warntop= quiet= @@ -38,21 +36,6 @@ usage() exit ${1:-0} } -is_active() -{ - [ -d "$git_dir/tg-create" ] || return 1 - [ -s "$git_dir/tg-create/name" ] || return 1 - [ -s "$git_dir/tg-create/deps" ] || return 1 - [ -s "$git_dir/tg-create/merge" ] || return 1 - [ -s "$git_dir/tg-create/msg" ] || return 1 - [ -s "$git_dir/tg-create/topmsg" ] || return 1 - [ -f "$git_dir/tg-create/nocommit" ] || return 1 - [ -f "$git_dir/tg-create/noedit" ] || return 1 - [ -f "$git_dir/tg-create/warntop" ] || return 1 - [ -f "$git_dir/tg-create/quiet" ] || return 1 - return 0 -} - quiet_info() { [ -n "$quiet" ] || info "$@" @@ -82,9 +65,6 @@ while [ $# -gt 0 ]; do case "$1" in branchtype=BASE branchdesc=base ;; - --continue) - continue=1 - ;; -m|--message|--message=*) case "$1" in --message=*) x="$1" @@ -164,9 +144,7 @@ while [ $# -gt 0 ]; do case "$1" in ;; esac; shift; done [ $# -gt 0 -o -z "$rname" ] || set -- "$rname" -[ $# -gt 0 -o -n "$remote$msg$msgfile$topmsg$topmsgfile$nocommit$nodeps" ] || continue=1 -[ -z "$continue" -o "$#$remote$msg$msgfile$topmsg$topmsgfile$nocommit$nodeps" = "0" ] || usage 1 -if [ -z "$continue" -a $# -gt 0 ]; then +if [ $# -gt 0 ]; then name="$1" shift if [ -z "$remote" -a "$1" = "-r" ]; then @@ -176,13 +154,12 @@ if [ -z "$continue" -a $# -gt 0 ]; then [ $# -eq 0 ] || shift fi fi -[ -n "$continue" -o -n "$name" ] || { err "no branch name given"; usage 1; } +[ -n "$name" ] || { err "no branch name given"; usage 1; } [ -z "$remote" -o -n "$rname" ] || rname="$name" [ -z "$remote" -o -z "$msg$msgfile$topmsg$topmsgfile$nocommit$nodeps" ] || { err "-r may not be combined with other options"; usage 1; } [ $# -eq 0 -o -z "$remote" ] || { err "deps not allowed with -r"; usage 1; } [ $# -le 1 -o -z "$nodeps" ] || { err "--no-deps allows at most one "; usage 1; } [ -z "$msg" -o -z "$msgfile" ] || die "only one -F or -m option is allowed" -[ -z "$continue" ] || is_active || die "no tg create is currently active" [ "$msgfile" != "-" -o "$topmsgfile" != "-" ] || { err "--message-file and --topmsg-file may not both be '-'"; usage 1; } ## Fast-track creating branches based on remote ones @@ -209,33 +186,19 @@ fi ## Auto-guess dependencies deps="$*" +[ "$deps" != "@" ] || deps="HEAD" if [ -z "$deps" ]; then - if [ -z "$name" ] && is_active; then - # We are setting up the base branch now; resume merge! - name="$(cat "$git_dir/tg-create/name")" - deps="$(cat "$git_dir/tg-create/deps")" - merge="$(cat "$git_dir/tg-create/merge")" - msg="$(cat "$git_dir/tg-create/msg")" - topmsg="$(cat "$git_dir/tg-create/topmsg")" - nocommit="$(cat "$git_dir/tg-create/nocommit")" - noedit="$(cat "$git_dir/tg-create/noedit")" - warntop="$(cat "$git_dir/tg-create/warntop")" - quiet="$(cat "$git_dir/tg-create/quiet")" - restarted=1 - quiet_info "Resuming $name setup..." + # The common case + [ -z "$name" ] && die "no branch name given" + if [ -n "$nodeps" ]; then + deps="HEAD" else - # The common case - [ -z "$name" ] && die "no branch name given" - if [ -n "$nodeps" ]; then - deps="HEAD" - else - head="$(git symbolic-ref --quiet HEAD)" || : - [ -z "$head" ] || git rev-parse --verify --quiet "$head" -- || - die "refusing to auto-depend on unborn branch (use --no-deps)" - deps="${head#refs/heads/}" - [ "$deps" != "$head" ] || die "refusing to auto-depend on non-branch ref (${head:-detached HEAD})" - quiet_info "automatically marking dependency on $deps" - fi + head="$(git symbolic-ref --quiet HEAD)" || : + [ -z "$head" ] || git rev-parse --verify --quiet "$head" -- || + die "refusing to auto-depend on unborn branch (use --no-deps)" + deps="${head#refs/heads/}" + [ "$deps" != "$head" ] || die "refusing to auto-depend on non-branch ref (${head:-detached HEAD})" + quiet_info "automatically marking dependency on $deps" fi fi @@ -254,7 +217,8 @@ if [ -n "$nodeps" ]; then fi # Non-remote branch set up requires a clean tree unless the single dep is the same tree as HEAD -[ -n "$restarted" ] || [ "$deps" = "HEAD" ] || { + +[ "$deps" = "HEAD" ] || { prefix=refs/heads/ [ -z "$nodeps" ] || prefix= [ $# -eq 1 -a "$(git rev-parse --quiet --verify "$prefix$deps^{tree}" --)" = "$(git rev-parse --quiet --verify HEAD^{tree} --)" ] || @@ -264,12 +228,13 @@ fi } } -[ -n "$merge" -o -n "$restarted" ] || merge="$deps " +[ -n "$merge" ] || merge="$deps " if [ -z "$nodeps" ]; then olddeps="$deps" deps= while read d && [ -n "$d" ]; do + [ "$d" != "@" ] || d="HEAD" if [ "$d" = "HEAD" ]; then sr="$(git symbolic-ref --quiet HEAD)" || : [ -z "$sr" ] || git rev-parse --verify --quiet "$sr" -- || @@ -306,16 +271,13 @@ if test="$(git symbolic-ref --quiet "$name" --)"; then case "$test" in name="${test#refs/heads/}" break;; esac; fi -! ref_exists "refs/heads/$name" || +! ref_exists "refs/heads/$name" || die "branch '$name' already exists" ! ref_exists "refs/$topbases/$name" || die "'$topbases/$name' already exists" [ -n "$force" ] || ! ref_exists "refs/tags/$name" || die "refusing to create branch with same name as existing tag '$name' without --force" -# Clean up any stale stuff -rm -rf "$git_dir/tg-create" - # Barf now rather than later if missing ident ensure_ident_available @@ -330,54 +292,53 @@ get_subject() : } -if [ -z "$restarted" ]; then - >"$git_dir/TG_EDITMSG" - if [ -n "$msgfile" ]; then - if [ "$msgfile" = "-" ]; then - git stripspace >"$git_dir/TG_EDITMSG" - else - git stripspace <"$msgfile" >"$git_dir/TG_EDITMSG" - fi - elif [ -n "$msg" ]; then - printf '%s\n' "$msg" | git stripspace >"$git_dir/TG_EDITMSG" - fi - if [ ! -s "$git_dir/TG_EDITMSG" ]; then - printf '%s\n' "tg create $name" | git stripspace >"$git_dir/TG_EDITMSG" +>"$git_dir/TG_EDITMSG" +if [ -n "$msgfile" ]; then + if [ "$msgfile" = "-" ]; then + git stripspace >"$git_dir/TG_EDITMSG" + else + git stripspace <"$msgfile" >"$git_dir/TG_EDITMSG" fi - msg="$(cat "$git_dir/TG_EDITMSG")" - rm -f "$git_dir/TG_EDITMSG" +elif [ -n "$msg" ]; then + printf '%s\n' "$msg" | git stripspace >"$git_dir/TG_EDITMSG" +fi +if [ ! -s "$git_dir/TG_EDITMSG" ]; then + printf '%s\n' "tg create $name" | git stripspace >"$git_dir/TG_EDITMSG" +fi +msg="$(cat "$git_dir/TG_EDITMSG")" +rm -f "$git_dir/TG_EDITMSG" - >"$git_dir/TG_EDITMSG" - if [ -n "$topmsgfile" ]; then - if [ "$topmsgfile" = "-" ]; then - git stripspace >"$git_dir/TG_EDITMSG" - else - git stripspace <"$topmsgfile" >"$git_dir/TG_EDITMSG" - fi - elif [ -n "$topmsg" ]; then - printf '%s\n' "$topmsg" | git stripspace >"$git_dir/TG_EDITMSG" - fi - if [ -s "$git_dir/TG_EDITMSG" ]; then - noedit=1 +>"$git_dir/TG_EDITMSG" +if [ -n "$topmsgfile" ]; then + if [ "$topmsgfile" = "-" ]; then + git stripspace >"$git_dir/TG_EDITMSG" else - author="$(git var GIT_AUTHOR_IDENT)" - author_addr="${author%> *}>" - { - echo "From: $author_addr" - ! header="$(git config topgit.to)" || echo "To: $header" - ! header="$(git config topgit.cc)" || echo "Cc: $header" - ! header="$(git config topgit.bcc)" || echo "Bcc: $header" - ! subject_prefix="$(git config topgit.subjectprefix)" || subject_prefix="$subject_prefix " - echo "Subject: [${subject_prefix}$branchtype] $name" - echo - echo "<$branchdesc description>" - echo - echo "Signed-off-by: $author_addr" - [ "$(git config --bool format.signoff)" = true ] && echo "Signed-off-by: $author_addr" - } | git stripspace >"$git_dir/TG_EDITMSG" + git stripspace <"$topmsgfile" >"$git_dir/TG_EDITMSG" fi - if [ -z "$noedit" ]; then - cat <>"$git_dir/TG_EDITMSG" +elif [ -n "$topmsg" ]; then + printf '%s\n' "$topmsg" | git stripspace >"$git_dir/TG_EDITMSG" +fi +if [ -s "$git_dir/TG_EDITMSG" ]; then + noedit=1 +else + author="$(git var GIT_AUTHOR_IDENT)" + author_addr="${author%> *}>" + { + echo "From: $author_addr" + ! header="$(git config topgit.to)" || echo "To: $header" + ! header="$(git config topgit.cc)" || echo "Cc: $header" + ! header="$(git config topgit.bcc)" || echo "Bcc: $header" + ! subject_prefix="$(git config topgit.subjectprefix)" || subject_prefix="$subject_prefix " + echo "Subject: [${subject_prefix}$branchtype] $name" + echo + echo "<$branchdesc description>" + echo + echo "Signed-off-by: $author_addr" + [ "$(git config --bool format.signoff)" = true ] && echo "Signed-off-by: $author_addr" + } | git stripspace >"$git_dir/TG_EDITMSG" +fi +if [ -z "$noedit" ]; then + cat <>"$git_dir/TG_EDITMSG" # Please enter the patch message for the new TopGit branch $name. # It will be stored in the .topmsg file and used to create the @@ -389,29 +350,27 @@ if [ -z "$restarted" ]; then # # tg create ${nodeps:+--no-deps }$name $deps EOT - run_editor "$git_dir/TG_EDITMSG" || - die "there was a problem with the editor '$tg_editor'" - git stripspace -s <"$git_dir/TG_EDITMSG" >"$git_dir/TG_EDITMSG"+ - mv -f "$git_dir/TG_EDITMSG"+ "$git_dir/TG_EDITMSG" - [ -s "$git_dir/TG_EDITMSG" ] || die "nothing to do" - fi - subj="$(get_subject <"$git_dir/TG_EDITMSG")" - if [ -z "$subj" ]; then - subj="$(sed -n "s/^[ $tab][ $tab]*//; 1p" <"$git_dir/TG_EDITMSG")"; - case "$subj" in "["*);;*) subj="[$branchtype] $subj"; esac - printf '%s\n' "Subject: $subj" "" >"$git_dir/TG_EDITMSG"+ - sed -n '2,$p' <"$git_dir/TG_EDITMSG" | git stripspace >>"$git_dir/TG_EDITMSG"+ - mv -f "$git_dir/TG_EDITMSG"+ "$git_dir/TG_EDITMSG" - warntop=1 - fi - topmsg="$(cat "$git_dir/TG_EDITMSG")" - rm -f "$git_dir/TG_EDITMSG" + run_editor "$git_dir/TG_EDITMSG" || + die "there was a problem with the editor '$tg_editor'" + git stripspace -s <"$git_dir/TG_EDITMSG" >"$git_dir/TG_EDITMSG"+ + mv -f "$git_dir/TG_EDITMSG"+ "$git_dir/TG_EDITMSG" + [ -s "$git_dir/TG_EDITMSG" ] || die "nothing to do" fi - +subj="$(get_subject <"$git_dir/TG_EDITMSG")" +if [ -z "$subj" ]; then + subj="$(sed -n "s/^[ $tab][ $tab]*//; 1p" <"$git_dir/TG_EDITMSG")"; + case "$subj" in "["*);;*) subj="[$branchtype] $subj"; esac + printf '%s\n' "Subject: $subj" "" >"$git_dir/TG_EDITMSG"+ + sed -n '2,$p' <"$git_dir/TG_EDITMSG" | git stripspace >>"$git_dir/TG_EDITMSG"+ + mv -f "$git_dir/TG_EDITMSG"+ "$git_dir/TG_EDITMSG" + warntop=1 +fi +topmsg="$(cat "$git_dir/TG_EDITMSG")" +rm -f "$git_dir/TG_EDITMSG" ## Find starting commit to create the base -if [ -n "$merge" -a -z "$restarted" ]; then +if [ -n "$merge" ]; then # Unshift the first item from the to-merge list branch="${merge%% *}" merge="${merge#* }" @@ -426,7 +385,6 @@ if [ -n "$merge" -a -z "$restarted" ]; then fi fi - ## Set up the topic branch init_reflog "refs/$topbases/$name" diff --git a/tg.sh b/tg.sh index e63c841..6badb07 100644 --- a/tg.sh +++ b/tg.sh @@ -1113,9 +1113,6 @@ check_status() if [ -e "$git_dir/tg-update" ]; then tg_state="update" tg_remove="$git_dir/tg-update" - elif [ -e "$git_dir/tg-create" ]; then - tg_state="create" - tg_remove="$git_dir/tg-create" fi tg_remove="${tg_remove#./}" } -- 2.11.4.GIT