This is a WIP. Signed-off-by: Ramkumar Ramachandra <artagnon@xxxxxxxxx> --- git-edit-link.sh | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 git-edit-link.sh diff --git a/git-edit-link.sh b/git-edit-link.sh new file mode 100644 index 0000000..3ff0e84 --- /dev/null +++ b/git-edit-link.sh @@ -0,0 +1,87 @@ +#!/bin/sh +# Copyright (c) 2013 Ramkumar Ramachandra + +dashless=$(basename "$0" | sed -e 's/-/ /') +USAGE='[--floating] [--ref-name <name>] [--checkout-rev <rev>] [--statthrough] <directory>' + +SUBDIRECTORY_OK=Yes +OPTIONS_SPEC= +START_DIR=`pwd` +. git-sh-setup +. git-sh-i18n +require_work_tree +cd_to_toplevel + +link_spec="$GIT_DIR/LINK_SPEC" + +read_and_verify_link_spec () { + test -f "$link_spec" || die "fatal: could not open $link_spec." + + ## TODO + ## Rules: + # upstream_url is a mandatory field; others are optional + # if floating is false, checkout_rev has to be a SHA-1 hex + # ref_name must be a valid name, and not conflict with an existing ref + + return 0; +} + +# Prepare an initial link_spec using the command-line options +rm -f "$link_spec" +touch "$link_spec" || die "fatal: could not create $link_spec." + +total_argc=$# +while test $# != 0 +do + case "$1" in + --checkout-rev) + shift + cat >>"$link_spec" <<-EOF + checkout_ref = $1 + EOF + ;; + --ref-name) + shift + cat >>"$link_spec" <<-EOF + ref_name = $1 + EOF + ;; + --floating) + cat >>"$link_spec" <<-\EOF + floating = 1 + EOF + ;; + --statthrough) + cat >>"$link_spec" <<-\EOF + statthrough = 1 + EOF + ;; + --) + shift + break + ;; + esac + shift +done + +link_directory="$1" +test -d "$link_directory" || die "fatal: $link_directory is not a valid directory." + +cd "$link_directory" && { + test -f "$link_directory/.git" && + test "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = true || + die "fatal: $link_directory is not a valid bare working tree." + + # Determine the upstream_url + upstream_url=$(git config --get remote.origin.url) +} + +test -z $upstream_url && +die "fatal: $link_directory does not have a configured upstream remote origin." +cat >>"$link_spec" <<-\EOF +upstream_url = $upstream_url +EOF + +# Launch the editor +git_editor "$link_spec" || die "$(gettext "Could not execute editor")" +read_and_verify_link_spec -- 1.8.2.380.g0d4e79b -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html