From: Stephen Robin <stephen.robin@gmail.com>
To: pyokagan@gmail.com
Cc: git@vger.kernel.org
Subject: [PATCH 6/6] parse-remote: dismantle git-parse-remote.sh
Date: Wed, 6 May 2015 01:00:53 +0100 [thread overview]
Message-ID: <1430870453-5408-7-git-send-email-stephen.robin@gmail.com> (raw)
In-Reply-To: <1430870453-5408-1-git-send-email-stephen.robin@gmail.com>
THIS PATCH SERIES IS NOT CODE-COMPLETE OR FULLY TESTED.
See code comments beginning TODO for work remaining.
Following the conversion of git-pull.sh to a builtin, git-parse-remote.sh
is only used from two places:
function error_on_missing_default_upstream is used within git-rebase.sh
only.
function get_default_remote is used within git-submodule.sh only.
Move these two functions into the scripts within which they're used, and
delete git-parse-remote.sh itself.
Signed-off-by: Stephen Robin <stephen.robin@gmail.com>
---
.gitignore | 1 -
Documentation/git-parse-remote.txt | 23 ----------
Makefile | 1 -
command-list.txt | 1 -
contrib/examples/git-parse-remote.sh | 89 ++++++++++++++++++++++++++++++++++++
git-parse-remote.sh | 89 ------------------------------------
git-rebase.sh | 36 ++++++++++++++-
git-submodule.sh | 8 +++-
8 files changed, 131 insertions(+), 117 deletions(-)
delete mode 100644 Documentation/git-parse-remote.txt
create mode 100644 contrib/examples/git-parse-remote.sh
delete mode 100644 git-parse-remote.sh
diff --git a/.gitignore b/.gitignore
index 6287647..dd25b33 100644
--- a/.gitignore
+++ b/.gitignore
@@ -104,7 +104,6 @@
/git-pack-redundant
/git-pack-objects
/git-pack-refs
-/git-parse-remote
/git-patch-id
/git-prune
/git-prune-packed
diff --git a/Documentation/git-parse-remote.txt b/Documentation/git-parse-remote.txt
deleted file mode 100644
index a45ea1e..0000000
--- a/Documentation/git-parse-remote.txt
+++ /dev/null
@@ -1,23 +0,0 @@
-git-parse-remote(1)
-===================
-
-NAME
-----
-git-parse-remote - Routines to help parsing remote repository access parameters
-
-
-SYNOPSIS
---------
-[verse]
-'. "$(git --exec-path)/git-parse-remote"'
-
-DESCRIPTION
------------
-This script is included in various scripts to supply
-routines to parse files under $GIT_DIR/remotes/ and
-$GIT_DIR/branches/ and configuration variables that are related
-to fetching, pulling and pushing.
-
-GIT
----
-Part of the linkgit:git[1] suite
diff --git a/Makefile b/Makefile
index 8d8fb3a..d41224c 100644
--- a/Makefile
+++ b/Makefile
@@ -481,7 +481,6 @@ SCRIPT_SH += git-submodule.sh
SCRIPT_SH += git-web--browse.sh
SCRIPT_LIB += git-mergetool--lib
-SCRIPT_LIB += git-parse-remote
SCRIPT_LIB += git-rebase--am
SCRIPT_LIB += git-rebase--interactive
SCRIPT_LIB += git-rebase--merge
diff --git a/command-list.txt b/command-list.txt
index f1eae08..273f69e 100644
--- a/command-list.txt
+++ b/command-list.txt
@@ -86,7 +86,6 @@ git-p4 foreignscminterface
git-pack-objects plumbingmanipulators
git-pack-redundant plumbinginterrogators
git-pack-refs ancillarymanipulators
-git-parse-remote synchelpers
git-patch-id purehelpers
git-prune ancillarymanipulators
git-prune-packed plumbingmanipulators
diff --git a/contrib/examples/git-parse-remote.sh b/contrib/examples/git-parse-remote.sh
new file mode 100644
index 0000000..55fe8d5
--- /dev/null
+++ b/contrib/examples/git-parse-remote.sh
@@ -0,0 +1,89 @@
+# This is a shell library to calculate the remote repository and
+# upstream branch that should be pulled by "git pull" from the current
+# branch.
+
+# git-ls-remote could be called from outside a git managed repository;
+# this would fail in that case and would issue an error message.
+GIT_DIR=$(git rev-parse -q --git-dir) || :;
+
+get_default_remote () {
+ curr_branch=$(git symbolic-ref -q HEAD)
+ curr_branch="${curr_branch#refs/heads/}"
+ origin=$(git config --get "branch.$curr_branch.remote")
+ echo ${origin:-origin}
+}
+
+get_remote_merge_branch () {
+ case "$#" in
+ 0|1)
+ origin="$1"
+ default=$(get_default_remote)
+ test -z "$origin" && origin=$default
+ curr_branch=$(git symbolic-ref -q HEAD) &&
+ [ "$origin" = "$default" ] &&
+ echo $(git for-each-ref --format='%(upstream)' $curr_branch)
+ ;;
+ *)
+ repo=$1
+ shift
+ ref=$1
+ # FIXME: It should return the tracking branch
+ # Currently only works with the default mapping
+ case "$ref" in
+ +*)
+ ref=$(expr "z$ref" : 'z+\(.*\)')
+ ;;
+ esac
+ expr "z$ref" : 'z.*:' >/dev/null || ref="${ref}:"
+ remote=$(expr "z$ref" : 'z\([^:]*\):')
+ case "$remote" in
+ '' | HEAD ) remote=HEAD ;;
+ heads/*) remote=${remote#heads/} ;;
+ refs/heads/*) remote=${remote#refs/heads/} ;;
+ refs/* | tags/* | remotes/* ) remote=
+ esac
+ [ -n "$remote" ] && case "$repo" in
+ .)
+ echo "refs/heads/$remote"
+ ;;
+ *)
+ echo "refs/remotes/$repo/$remote"
+ ;;
+ esac
+ esac
+}
+
+error_on_missing_default_upstream () {
+ cmd="$1"
+ op_type="$2"
+ op_prep="$3"
+ example="$4"
+ branch_name=$(git symbolic-ref -q HEAD)
+ # If there's only one remote, use that in the suggestion
+ remote="<remote>"
+ if test $(git remote | wc -l) = 1
+ then
+ remote=$(git remote)
+ fi
+
+ if test -z "$branch_name"
+ then
+ echo "You are not currently on a branch. Please specify which
+branch you want to $op_type $op_prep. See git-${cmd}(1) for details.
+
+ $example
+"
+ else
+ echo "There is no tracking information for the current branch.
+Please specify which branch you want to $op_type $op_prep.
+See git-${cmd}(1) for details
+
+ $example
+
+If you wish to set tracking information for this branch you can do so with:
+
+ git branch --set-upstream-to=$remote/<branch> ${branch_name#refs/heads/}
+"
+ fi
+ exit 1
+}
diff --git a/git-parse-remote.sh b/git-parse-remote.sh
deleted file mode 100644
index 55fe8d5..0000000
--- a/git-parse-remote.sh
+++ /dev/null
@@ -1,89 +0,0 @@
-# This is a shell library to calculate the remote repository and
-# upstream branch that should be pulled by "git pull" from the current
-# branch.
-
-# git-ls-remote could be called from outside a git managed repository;
-# this would fail in that case and would issue an error message.
-GIT_DIR=$(git rev-parse -q --git-dir) || :;
-
-get_default_remote () {
- curr_branch=$(git symbolic-ref -q HEAD)
- curr_branch="${curr_branch#refs/heads/}"
- origin=$(git config --get "branch.$curr_branch.remote")
- echo ${origin:-origin}
-}
-
-get_remote_merge_branch () {
- case "$#" in
- 0|1)
- origin="$1"
- default=$(get_default_remote)
- test -z "$origin" && origin=$default
- curr_branch=$(git symbolic-ref -q HEAD) &&
- [ "$origin" = "$default" ] &&
- echo $(git for-each-ref --format='%(upstream)' $curr_branch)
- ;;
- *)
- repo=$1
- shift
- ref=$1
- # FIXME: It should return the tracking branch
- # Currently only works with the default mapping
- case "$ref" in
- +*)
- ref=$(expr "z$ref" : 'z+\(.*\)')
- ;;
- esac
- expr "z$ref" : 'z.*:' >/dev/null || ref="${ref}:"
- remote=$(expr "z$ref" : 'z\([^:]*\):')
- case "$remote" in
- '' | HEAD ) remote=HEAD ;;
- heads/*) remote=${remote#heads/} ;;
- refs/heads/*) remote=${remote#refs/heads/} ;;
- refs/* | tags/* | remotes/* ) remote=
- esac
- [ -n "$remote" ] && case "$repo" in
- .)
- echo "refs/heads/$remote"
- ;;
- *)
- echo "refs/remotes/$repo/$remote"
- ;;
- esac
- esac
-}
-
-error_on_missing_default_upstream () {
- cmd="$1"
- op_type="$2"
- op_prep="$3"
- example="$4"
- branch_name=$(git symbolic-ref -q HEAD)
- # If there's only one remote, use that in the suggestion
- remote="<remote>"
- if test $(git remote | wc -l) = 1
- then
- remote=$(git remote)
- fi
-
- if test -z "$branch_name"
- then
- echo "You are not currently on a branch. Please specify which
-branch you want to $op_type $op_prep. See git-${cmd}(1) for details.
-
- $example
-"
- else
- echo "There is no tracking information for the current branch.
-Please specify which branch you want to $op_type $op_prep.
-See git-${cmd}(1) for details
-
- $example
-
-If you wish to set tracking information for this branch you can do so with:
-
- git branch --set-upstream-to=$remote/<branch> ${branch_name#refs/heads/}
-"
- fi
- exit 1
-}
diff --git a/git-rebase.sh b/git-rebase.sh
index 55da9db..7b157ec 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -209,6 +209,41 @@ run_pre_rebase_hook () {
fi
}
+error_on_missing_default_upstream () {
+ cmd="$1"
+ op_type="$2"
+ op_prep="$3"
+ example="$4"
+ branch_name=$(git symbolic-ref -q HEAD)
+ # If there's only one remote, use that in the suggestion
+ remote="<remote>"
+ if test $(git remote | wc -l) = 1
+ then
+ remote=$(git remote)
+ fi
+
+ if test -z "$branch_name"
+ then
+ echo "You are not currently on a branch. Please specify which
+branch you want to $op_type $op_prep. See git-${cmd}(1) for details.
+
+ $example
+"
+ else
+ echo "There is no tracking information for the current branch.
+Please specify which branch you want to $op_type $op_prep.
+See git-${cmd}(1) for details
+
+ $example
+
+If you wish to set tracking information for this branch you can do so with:
+
+ git branch --set-upstream-to=$remote/<branch> ${branch_name#refs/heads/}
+"
+ fi
+ exit 1
+}
+
test -f "$apply_dir"/applying &&
die "$(gettext "It looks like git-am is in progress. Cannot rebase.")"
@@ -446,7 +481,6 @@ then
if ! upstream_name=$(git rev-parse --symbolic-full-name \
--verify -q @{upstream} 2>/dev/null)
then
- . git-parse-remote
error_on_missing_default_upstream "rebase" "rebase" \
"against" "git rebase <branch>"
fi
diff --git a/git-submodule.sh b/git-submodule.sh
index 36797c3..08c31eb 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -17,7 +17,6 @@ OPTIONS_SPEC=
SUBDIRECTORY_OK=Yes
. git-sh-setup
. git-sh-i18n
-. git-parse-remote
require_work_tree
wt_prefix=$(git rev-parse --show-prefix)
cd_to_toplevel
@@ -37,6 +36,13 @@ prefix=
custom_name=
depth=
+get_default_remote () {
+ curr_branch=$(git symbolic-ref -q HEAD)
+ curr_branch="${curr_branch#refs/heads/}"
+ origin=$(git config --get "branch.$curr_branch.remote")
+ echo ${origin:-origin}
+}
+
# The function takes at most 2 arguments. The first argument is the
# URL that navigates to the submodule origin repo. When relative, this URL
# is relative to the superproject origin URL repo. The second up_path
--
2.4.0.7.gf20f26f
next prev parent reply other threads:[~2015-05-06 0:01 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-27 19:50 GSoC 2015: 2 accepted proposals Matthieu Moy
2015-04-28 8:58 ` Paul Tan
2015-04-29 15:27 ` Johannes Schindelin
2015-05-06 0:00 ` [PATCH 0/6] Make pull a builtin Stephen Robin
2015-05-06 0:00 ` [PATCH 1/6] merge: tidy up options Stephen Robin
2015-05-06 0:00 ` [PATCH 2/6] merge: move error message given when a merge needs committing to advice.c Stephen Robin
2015-05-06 0:00 ` [PATCH 3/6] merge-base: split handle_fork_point to make reuse easier Stephen Robin
2015-05-06 0:00 ` [PATCH 4/6] pull: reimplement as a builtin in C Stephen Robin
2015-05-06 0:00 ` [PATCH 5/6] pull: allow interactive rebase Stephen Robin
2015-05-06 5:43 ` Johannes Schindelin
2015-05-06 0:00 ` Stephen Robin [this message]
2015-05-06 4:27 ` [PATCH 0/6] Make pull a builtin Paul Tan
2015-04-28 12:17 ` GSoC 2015: 2 accepted proposals karthik nayak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1430870453-5408-7-git-send-email-stephen.robin@gmail.com \
--to=stephen.robin@gmail.com \
--cc=git@vger.kernel.org \
--cc=pyokagan@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).