git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [RFC PATCH 0/4] Add alias option to git branch
@ 2019-03-04 15:45 Kenneth Cochran
  2019-03-04 15:47 ` [RFC PATCH 1/4] " Kenneth Cochran
  2019-03-05 13:21 ` [RFC PATCH 0/4] " Junio C Hamano
  0 siblings, 2 replies; 11+ messages in thread
From: Kenneth Cochran @ 2019-03-04 15:45 UTC (permalink / raw)
  To: git; +Cc: Sahil Dua, Duy Nguyen, Jeff King

From c1bad54b29ae1c1d8548d248f6ecaa5959e55f7b Mon Sep 17 00:00:00 2001
From: Kenneth Cochran <kenneth.cochran101@gmail.com>
Date: Mon, 4 Mar 2019 09:40:22 -0600
Subject: [RFC PATCH 0/4] Add alias option to git branch
Cc: Sahil Dua <sahildua2305@gmail.com>,
    Duy Nguyen <pclouds@gmail.com>,
    Jeff King <peff@peff.net>

I find myself often using git symbolic-ref to get around work requirements to use branch names that are not very human friendly.
There are a few problems with this:
	- There’s a lot of text to type
	- Mistyping certain parts (heads/refs) will do things other than create a branch alias
	- It will happily overwrite an existing branch
	- Deleting one that is checked out will put HEAD in an invalid state.

I think this solution is much better; however, I’m not super familiar with the codebase, so I’m sure it can be improved.
I’d appreciate any feedback.

Kenneth Cochran (4):
  branch: add "--alias" option to create an alias
  refs: add function to iteratively dereference symref chain
  worktree: symref should be found anywhere in chain
  branch: disallow accidentally breaking symrefs

 Documentation/git-branch.txt |  8 ++++
 builtin/branch.c             | 49 ++++++++++++++++++++-
 refs.c                       | 28 ++++++++++++
 refs.h                       | 13 ++++++
 t/t3207-branch-alias.sh      | 83 ++++++++++++++++++++++++++++++++++++
 worktree.c                   | 18 +++++---
 6 files changed, 191 insertions(+), 8 deletions(-)
 create mode 100755 t/t3207-branch-alias.sh

-- 
2.17.1



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [RFC PATCH 1/4] Add alias option to git branch
  2019-03-04 15:45 [RFC PATCH 0/4] Add alias option to git branch Kenneth Cochran
@ 2019-03-04 15:47 ` Kenneth Cochran
  2019-03-04 15:48   ` [RFC PATCH 2/4] " Kenneth Cochran
  2019-03-05 13:21 ` [RFC PATCH 0/4] " Junio C Hamano
  1 sibling, 1 reply; 11+ messages in thread
From: Kenneth Cochran @ 2019-03-04 15:47 UTC (permalink / raw)
  To: Kenneth Cochran; +Cc: git, Sahil Dua, Duy Nguyen, Jeff King

From 2f6409a39b24db826a22d2813ec8d5de46723500 Mon Sep 17 00:00:00 2001
From: Kenneth Cochran <kenneth.cochran101@gmail.com>
Date: Tue, 26 Feb 2019 04:41:22 -0600
Subject: [RFC PATCH 1/4] branch: add "--alias" option to create an alias
Cc: Sahil Dua <sahildua2305@gmail.com>,
    Duy Nguyen <pclouds@gmail.com>,
    Jeff King <peff@peff.net>

Often, people have to use long or unweildly branch names
e.g. `feature/<bug_number>`. When working locally, it's nice to be
able to refer to that by something more friendly. It's already possible
to do this, with `git symbolic-ref refs/heads/alias_name refs/heads/branch_name`
I see three problems with this current approach:
  1. Typing out "refs/heads/" is tedious and error prone
  2. git will willingly overwrite existing branch names
  3. Deleting a checked out symref leaves head in an invalid state.

This commit solves the first two of the above issues.
I've implemented this as a new option for git branch, since this seemed like the
best place for it. We'll still need additional work to improve how git handles
deleting checked out symrefs.

These changes were originally proposed by Phil Sainty, but it doesn't seem
like there was ever any discussion about it:
https://www.mail-archive.com/git@vger.kernel.org/msg161274.html

Reported-by: Phil Sainty <psainty@orcon.net.nz>
Signed-off-by: Kenneth Cochran <kenneth.cochran101@gmail.com>
---
 Documentation/git-branch.txt |  8 +++++
 builtin/branch.c             | 29 ++++++++++++++++--
 t/t3207-branch-alias.sh      | 58 ++++++++++++++++++++++++++++++++++++
 3 files changed, 93 insertions(+), 2 deletions(-)
 create mode 100755 t/t3207-branch-alias.sh

diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt
index 3bd83a7cbd..0476c8567b 100644
--- a/Documentation/git-branch.txt
+++ b/Documentation/git-branch.txt
@@ -19,6 +19,7 @@ SYNOPSIS
 'git branch' --unset-upstream [<branchname>]
 'git branch' (-m | -M) [<oldbranch>] <newbranch>
 'git branch' (-c | -C) [<oldbranch>] <newbranch>
+'git branch' --alias <aliasname> [<branchname>]
 'git branch' (-d | -D) [-r] <branchname>...
 'git branch' --edit-description [<branchname>]
 
@@ -69,6 +70,10 @@ The `-c` and `-C` options have the exact same semantics as `-m` and
 `-M`, except instead of the branch being renamed it along with its
 config and reflog will be copied to a new name.
 
+With a `--alias` option, a symbolic ref with `<aliasname>` will be
+created. You may specify a branch to create the alias for. If one is
+not specified, the currently checked out branch is assumed.
+
 With a `-d` or `-D` option, `<branchname>` will be deleted.  You may
 specify more than one branch for deletion.  If the branch currently
 has a reflog then the reflog will also be deleted.
@@ -124,6 +129,9 @@ OPTIONS
 -C::
 	Shortcut for `--copy --force`.
 
+--alias::
+	Create an alias for a branch.
+
 --color[=<when>]::
 	Color branches to highlight current, local, and
 	remote-tracking branches.
diff --git a/builtin/branch.c b/builtin/branch.c
index 1be727209b..4b8b8fc08f 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -547,6 +547,20 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int
 	strbuf_release(&newsection);
 }
 
+static void create_branch_alias(const char* branch_name, const char* alias_name) {
+	struct strbuf branch_ref = STRBUF_INIT;
+	struct strbuf alias_ref = STRBUF_INIT;
+
+	if(!validate_branchname(branch_name, &branch_ref))
+		die(_("%s is not a valid branch"), branch_name);
+	validate_new_branchname(alias_name, &alias_ref, 0);
+	create_symref(alias_ref.buf, branch_ref.buf, "");
+
+	strbuf_release(&branch_ref);
+	strbuf_release(&alias_ref);
+	printf(_("%s created as an alias for %s\n"), alias_name, branch_name);
+}
+
 static GIT_PATH_FUNC(edit_description, "EDIT_DESCRIPTION")
 
 static int edit_branch_description(const char *branch_name)
@@ -580,7 +594,7 @@ static int edit_branch_description(const char *branch_name)
 
 int cmd_branch(int argc, const char **argv, const char *prefix)
 {
-	int delete = 0, rename = 0, copy = 0, force = 0, list = 0;
+	int delete = 0, rename = 0, copy = 0, force = 0, list = 0, alias = 0;
 	int reflog = 0, edit_description = 0;
 	int quiet = 0, unset_upstream = 0;
 	const char *new_upstream = NULL;
@@ -617,6 +631,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 		OPT_BIT('D', NULL, &delete, N_("delete branch (even if not merged)"), 2),
 		OPT_BIT('m', "move", &rename, N_("move/rename a branch and its reflog"), 1),
 		OPT_BIT('M', NULL, &rename, N_("move/rename a branch, even if target exists"), 2),
+		OPT_BOOL(0, "alias", &alias, N_("create an alias for a branch")),
 		OPT_BIT('c', "copy", &copy, N_("copy a branch and its reflog"), 1),
 		OPT_BIT('C', NULL, &copy, N_("copy a branch, even if target exists"), 2),
 		OPT_BOOL('l', "list", &list, N_("list branch names")),
@@ -662,7 +677,8 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 	argc = parse_options(argc, argv, prefix, options, builtin_branch_usage,
 			     0);
 
-	if (!delete && !rename && !copy && !edit_description && !new_upstream && !unset_upstream && argc == 0)
+	if (!delete && !rename && !copy && !edit_description && !new_upstream && !unset_upstream &&
+	    !alias && argc == 0)
 		list = 1;
 
 	if (filter.with_commit || filter.merge != REF_FILTER_MERGED_NONE || filter.points_at.nr ||
@@ -762,6 +778,15 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 			copy_or_rename_branch(argv[0], argv[1], 0, rename > 1);
 		else
 			die(_("too many arguments for a rename operation"));
+	} else if (alias) {
+		if (!argc)
+			die(_("alias name required"));
+		else if (argc == 1)
+			create_branch_alias(head, argv[0]);
+		else if (argc == 2)
+			create_branch_alias(argv[1], argv[0]);
+		else
+			die(_("too many arguments for an alias operation"));
 	} else if (new_upstream) {
 		struct branch *branch = branch_get(argv[0]);
 
diff --git a/t/t3207-branch-alias.sh b/t/t3207-branch-alias.sh
new file mode 100755
index 0000000000..9d4c8c2914
--- /dev/null
+++ b/t/t3207-branch-alias.sh
@@ -0,0 +1,58 @@
+#!/bin/sh
+#
+# Copyright (c) 2005 Amos Waterland
+#
+
+test_description='git branch assorted tests'
+
+. ./test-lib.sh
+. "$TEST_DIRECTORY"/lib-rebase.sh
+
+test_expect_success 'prepare a trivial repository' '
+	echo Hello >A &&
+	git update-index --add A &&
+	git commit -m "Initial commit." &&
+	echo World >>A &&
+	git update-index --add A &&
+	git commit -m "Second commit." &&
+	HEAD=$(git rev-parse --verify HEAD)
+'
+
+test_expect_success 'git branch --alias' '
+	test_must_fail git branch --alias
+'
+
+test_expect_success 'git branch --alias sym' '
+	echo "sym created as an alias for master" >expect &&
+	git branch --alias sym >actual &&
+	test_i18ncmp expect actual &&
+	echo $HEAD >expect &&
+	git rev-parse --verify sym >actual &&
+	test_i18ncmp expect actual
+'
+
+test_expect_success 'git branch --alias sym1 brnch' '
+	git branch brnch &&
+	echo "sym1 created as an alias for brnch" >expect &&
+	git branch --alias sym1 brnch >actual &&
+	test_i18ncmp expect actual &&
+	git rev-parse --verify brnch >expect &&
+	git rev-parse --verify sym1 >actual &&
+	test_i18ncmp expect actual
+'
+
+test_expect_success 'git branch --alias sym2 brnch2 third_arg' '
+	test_must_fail git branch --alias sym2 brnch2 third_arg
+'
+
+test_expect_success 'git branch --alias refuses to overwrite existing branch' '
+	git branch bre &&
+	test_must_fail git branch --alias bre
+'
+
+test_expect_success 'git branch --alias refuses to overwrite existing symref' '
+	git branch --alias syme &&
+	test_must_fail git branch --alias syme
+'
+
+test_done
-- 
2.17.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [RFC PATCH 2/4] Add alias option to git branch
  2019-03-04 15:47 ` [RFC PATCH 1/4] " Kenneth Cochran
@ 2019-03-04 15:48   ` Kenneth Cochran
  2019-03-04 15:49     ` [RFC PATCH 3/4] " Kenneth Cochran
  0 siblings, 1 reply; 11+ messages in thread
From: Kenneth Cochran @ 2019-03-04 15:48 UTC (permalink / raw)
  To: Kenneth Cochran; +Cc: git, Sahil Dua, Duy Nguyen, Jeff King

From 5aa6f037642df3b358ab659d17b5fb5bc7936f0f Mon Sep 17 00:00:00 2001
From: Kenneth Cochran <kenneth.cochran101@gmail.com>
Date: Sun, 3 Mar 2019 15:05:11 -0600
Subject: [RFC PATCH 2/4] refs: add function to iteratively dereference symref
 chain
Cc: Sahil Dua <sahildua2305@gmail.com>,
    Duy Nguyen <pclouds@gmail.com>,
    Jeff King <peff@peff.net>

As far as I can tell, currently, there's not really any way
to run something once per symref in a symref chain. This adds that
ability.

This will be useful for instance to improve how `git branch -d`
handles a checked out symref.

Signed-off-by: Kenneth Cochran <kenneth.cochran101@gmail.com>
---
 refs.c | 28 ++++++++++++++++++++++++++++
 refs.h | 13 +++++++++++++
 2 files changed, 41 insertions(+)

diff --git a/refs.c b/refs.c
index 142888a40a..18a222d76a 100644
--- a/refs.c
+++ b/refs.c
@@ -1466,6 +1466,34 @@ static int do_for_each_ref(struct ref_store *refs, const char *prefix,
 					do_for_each_ref_helper, &hp);
 }
 
+int refs_for_each_ref_in_chain(struct ref_store *refs, each_ref_fn fn,
+			       void *cb_data, const char *starting_ref)
+{
+	int symref_count;
+	struct object_id oid;
+	int flags;
+	const char *ref_name = xstrdup(starting_ref);
+	int res;
+
+	for (symref_count = 0; symref_count < SYMREF_MAXDEPTH; symref_count++) {
+		res = fn(ref_name, &oid, flags, cb_data);
+		ref_name = refs_resolve_ref_unsafe(refs, ref_name, RESOLVE_REF_NO_RECURSE,
+						   &oid, &flags);
+
+		if (res)
+			return res;
+		if (!(flags & REF_ISSYMREF))
+			break;
+	}
+	return 0;
+}
+
+int for_each_ref_in_chain(each_ref_fn fn, void *cb_data, const char *starting_ref)
+{
+	return refs_for_each_ref_in_chain(get_main_ref_store(the_repository), fn,
+					  cb_data, starting_ref);
+}
+
 int refs_for_each_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data)
 {
 	return do_for_each_ref(refs, "", fn, 0, 0, cb_data);
diff --git a/refs.h b/refs.h
index 308fa1f03b..66ccb85e8d 100644
--- a/refs.h
+++ b/refs.h
@@ -327,6 +327,19 @@ int for_each_glob_ref_in(each_ref_fn fn, const char *pattern,
 int head_ref_namespaced(each_ref_fn fn, void *cb_data);
 int for_each_namespaced_ref(each_ref_fn fn, void *cb_data);
 
+/*
+ * Iteratively calls fn with each reference in a symref chain.
+ * Iteration will continue until one of the following occurs:
+ * - SYMREF_MAXDEPTH is reached
+ * - A non-symbolic ref is reached (fn will be called with this before returning)
+ * - fn returns a non 0 value
+ *
+ * Will always return 0 unless fn returns a non-zero value.
+ */
+int refs_for_each_ref_in_chain(struct ref_store *refs, each_ref_fn fn,
+			       void *cb_data, const char *starting_ref);
+int for_each_ref_in_chain(each_ref_fn fn, void *cb_data, const char *starting_ref);
+
 /* can be used to learn about broken ref and symref */
 int refs_for_each_rawref(struct ref_store *refs, each_ref_fn fn, void *cb_data);
 int for_each_rawref(each_ref_fn fn, void *cb_data);
-- 
2.17.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [RFC PATCH 3/4] Add alias option to git branch
  2019-03-04 15:48   ` [RFC PATCH 2/4] " Kenneth Cochran
@ 2019-03-04 15:49     ` Kenneth Cochran
  2019-03-04 15:49       ` [RFC PATCH 4/4] " Kenneth Cochran
  0 siblings, 1 reply; 11+ messages in thread
From: Kenneth Cochran @ 2019-03-04 15:49 UTC (permalink / raw)
  To: Kenneth Cochran; +Cc: git, Sahil Dua, Duy Nguyen, Jeff King

From 9f9b9010cb0b8c2874428d2f4bd21f06f747bfee Mon Sep 17 00:00:00 2001
From: Kenneth Cochran <kenneth.cochran101@gmail.com>
Date: Sun, 3 Mar 2019 15:34:20 -0600
Subject: [RFC PATCH 3/4] worktree: symref should be found anywhere in chain
Cc: Sahil Dua <sahildua2305@gmail.com>,
    Duy Nguyen <pclouds@gmail.com>,
    Jeff King <peff@peff.net>

Currently, when searching for a shared symref, a symref chain is
fully dereferenced before checking the name. This poses problems for
`git branch -d` which will happily delete a checked out symref.

The existing behaviour (recognizing a non-symbolic ref by the same name)
still exists, but it will now also find any symref that is in between the
starting symref and the first non-symbolic ref.

Concretely, for the following chain
HEAD -> symref1 -> symref2 -> master
previously the function was only able to find master.
With these changes applied, it will be able to find any of the above references.

Signed-off-by: Kenneth Cochran <kenneth.cochran101@gmail.com>
---
 t/t3207-branch-alias.sh | 13 +++++++++++++
 worktree.c              | 18 ++++++++++++------
 2 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/t/t3207-branch-alias.sh b/t/t3207-branch-alias.sh
index 9d4c8c2914..c1edeed4eb 100755
--- a/t/t3207-branch-alias.sh
+++ b/t/t3207-branch-alias.sh
@@ -55,4 +55,17 @@ test_expect_success 'git branch --alias refuses to overwrite existing symref' '
 	test_must_fail git branch --alias syme
 '
 
+test_expect_success 'git branch -d refuses to delete a checked out symref' '
+	git branch --alias symd &&
+	git checkout symd &&
+	test_must_fail git branch -d symd
+'
+
+test_expect_success 'git branch -d refuses to delete an indirectly checked out symref' '
+	git symbolic-ref refs/heads/symd2 refs/heads/symd &&
+	git checkout symd2 &&
+	test_must_fail git branch -d symd2 &&
+	test_must_fail git branch -d symd
+'
+
 test_done
diff --git a/worktree.c b/worktree.c
index d6a0ee7f73..b58325c6c1 100644
--- a/worktree.c
+++ b/worktree.c
@@ -387,6 +387,17 @@ int is_worktree_being_bisected(const struct worktree *wt,
 	return found_rebase;
 }
 
+static int find_symref_by_name(const char *ref_name, const struct object_id *oid,
+			       int flags, void *cb_data)
+{
+	const char *target = (const char *)cb_data;
+
+	if ((flags & REF_ISSYMREF) && !strcmp(target, ref_name))
+		return 1;
+	else
+		return 0;
+}
+
 /*
  * note: this function should be able to detect shared symref even if
  * HEAD is temporarily detached (e.g. in the middle of rebase or
@@ -406,9 +417,7 @@ const struct worktree *find_shared_symref(const char *symref,
 
 	for (i = 0; worktrees[i]; i++) {
 		struct worktree *wt = worktrees[i];
-		const char *symref_target;
 		struct ref_store *refs;
-		int flags;
 
 		if (wt->is_bare)
 			continue;
@@ -425,10 +434,7 @@ const struct worktree *find_shared_symref(const char *symref,
 		}
 
 		refs = get_worktree_ref_store(wt);
-		symref_target = refs_resolve_ref_unsafe(refs, symref, 0,
-							NULL, &flags);
-		if ((flags & REF_ISSYMREF) &&
-		    symref_target && !strcmp(symref_target, target)) {
+		if(refs_for_each_ref_in_chain(refs, find_symref_by_name, (void *)target, symref)) {
 			existing = wt;
 			break;
 		}
-- 
2.17.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [RFC PATCH 4/4] Add alias option to git branch
  2019-03-04 15:49     ` [RFC PATCH 3/4] " Kenneth Cochran
@ 2019-03-04 15:49       ` Kenneth Cochran
  2019-03-04 16:38         ` Kenneth Cochran
       [not found]         ` <CAJ145vUChd7+5QkmJsOK3bzZsudWfzZYp5wHZDzoq8SKSv0g0A@mail.gmail.com>
  0 siblings, 2 replies; 11+ messages in thread
From: Kenneth Cochran @ 2019-03-04 15:49 UTC (permalink / raw)
  To: Kenneth Cochran; +Cc: git, Sahil Dua, Duy Nguyen, Jeff King

From c1bad54b29ae1c1d8548d248f6ecaa5959e55f7b Mon Sep 17 00:00:00 2001
From: Kenneth Cochran <kenneth.cochran101@gmail.com>
Date: Mon, 4 Mar 2019 01:08:46 -0600
Subject: [RFC PATCH 4/4] branch: disallow accidentally breaking symrefs
Cc: Sahil Dua <sahildua2305@gmail.com>,
    Duy Nguyen <pclouds@gmail.com>,
    Jeff King <peff@peff.net>

Currently, symrefs are ignored when deleting a branch, making
it possible to accidentally create dangling symrefs without any
warning.

These changes give an error if a branch deletion operation would
create a dangling symref, unless the user specifies to force the
delete anyways.

Signed-off-by: Kenneth Cochran <kenneth.cochran101@gmail.com>
---
 builtin/branch.c        | 20 ++++++++++++++++++++
 t/t3207-branch-alias.sh | 12 ++++++++++++
 2 files changed, 32 insertions(+)

diff --git a/builtin/branch.c b/builtin/branch.c
index 4b8b8fc08f..5c05ccd5e9 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -233,6 +233,11 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
 		if (kinds == FILTER_REFS_BRANCHES) {
 			const struct worktree *wt =
 				find_shared_symref("HEAD", name);
+			char *buf;
+			size_t len;
+			FILE *memstream;
+			int cont = 0;
+
 			if (wt) {
 				error(_("Cannot delete branch '%s' "
 					"checked out at '%s'"),
@@ -240,6 +245,21 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
 				ret = 1;
 				continue;
 			}
+
+			memstream = open_memstream(&buf, &len);
+			warn_dangling_symref(memstream, "%s", name);
+			fclose(memstream);
+			buf[strcspn(buf, "\n")] = '\0';
+			if (len > 0 && !force) {
+				cont = 1;
+				error(_("Deleting branch '%s' would leave dangling symrefs.\n"
+					"If you're sure you want to delete it, run 'git branch -D %s'\n"
+					"The following symrefs would be left dangling:\n%s"),
+				      bname.buf, bname.buf, buf);
+			}
+			free(buf);
+			if (cont)
+				continue;
 		}
 
 		target = resolve_refdup(name,
diff --git a/t/t3207-branch-alias.sh b/t/t3207-branch-alias.sh
index c1edeed4eb..2f3a7b398b 100755
--- a/t/t3207-branch-alias.sh
+++ b/t/t3207-branch-alias.sh
@@ -68,4 +68,16 @@ test_expect_success 'git branch -d refuses to delete an indirectly checked out s
 	test_must_fail git branch -d symd
 '
 
+test_expect_success 'git branch -d refuses to create a dangling symref' '
+	git branch dangling_parent &&
+	git branch --alias dangling dangling_parent &&
+	git branch -d dangling_parent &&
+	test_path_is_file .git/refs/heads/dangling_parent
+'
+
+test_expect_success 'git branch -D forces creation of dangling symref' '
+	git branch -D dangling_parent &&
+	test_must_fail test_path_is_file .git/refs/heads/dangling_parent
+'
+
 test_done
-- 
2.17.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [RFC PATCH 4/4] Add alias option to git branch
  2019-03-04 15:49       ` [RFC PATCH 4/4] " Kenneth Cochran
@ 2019-03-04 16:38         ` Kenneth Cochran
       [not found]         ` <CAJ145vUChd7+5QkmJsOK3bzZsudWfzZYp5wHZDzoq8SKSv0g0A@mail.gmail.com>
  1 sibling, 0 replies; 11+ messages in thread
From: Kenneth Cochran @ 2019-03-04 16:38 UTC (permalink / raw)
  To: Kenneth Cochran; +Cc: git, Sahil Dua, Duy Nguyen, Jeff King, Phil Sainty

Adding Phil for comments

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [RFC PATCH 4/4] Add alias option to git branch
       [not found]         ` <CAJ145vUChd7+5QkmJsOK3bzZsudWfzZYp5wHZDzoq8SKSv0g0A@mail.gmail.com>
@ 2019-03-04 19:33           ` Phil Sainty
  2019-03-04 19:52             ` Kenneth Cochran
  0 siblings, 1 reply; 11+ messages in thread
From: Phil Sainty @ 2019-03-04 19:33 UTC (permalink / raw)
  To: Kenneth Cochran; +Cc: git, Sahil Dua, Duy Nguyen, Jeff King

5/03/19 5:23 AM, Kenneth Cochran wrote:
> Adding Phil for comments

Thank you for following this up, Kenneth.  I'll do some testing with
your patch sometime soon.

I've realised that the last version of my script that I posted to the
mailing list was buggy, and that in wanting to hold off sending another
version for a little while in case I found more bugs, I in fact failed
to send a fixed version at all.

This is probably not relevant to your patches; but just in case,
the up to date code for that script is here:

https://stackoverflow.com/a/23532744/324105

and the fixes since v1.11 were:

* Change incorrect uses of git show-ref, introduced by v1.10 (including
  effective regression of v1.08), to use git symbolic-ref instead.

* Fix the option handling for '--', and added it to the help text.


-Phil

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [RFC PATCH 4/4] Add alias option to git branch
  2019-03-04 19:33           ` Phil Sainty
@ 2019-03-04 19:52             ` Kenneth Cochran
  0 siblings, 0 replies; 11+ messages in thread
From: Kenneth Cochran @ 2019-03-04 19:52 UTC (permalink / raw)
  To: Phil Sainty; +Cc: git, Sahil Dua, Duy Nguyen, Jeff King

On Mon, Mar 4, 2019 at 1:34 PM Phil Sainty <psainty@orcon.net.nz> wrote:
>
> 5/03/19 5:23 AM, Kenneth Cochran wrote:
> > Adding Phil for comments
>
> Thank you for following this up, Kenneth.  I'll do some testing with
> your patch sometime soon.

Thanks! Any feedback is appreciated.

>
> I've realised that the last version of my script that I posted to the
> mailing list was buggy, and that in wanting to hold off sending another
> version for a little while in case I found more bugs, I in fact failed
> to send a fixed version at all.
>
> This is probably not relevant to your patches; but just in case,
> the up to date code for that script is here:
>
> https://stackoverflow.com/a/23532744/324105

This stack overflow post was actually what led me to the git mailing
list in the first place :)

>
> and the fixes since v1.11 were:
>
> * Change incorrect uses of git show-ref, introduced by v1.10 (including
>   effective regression of v1.08), to use git symbolic-ref instead.
>
> * Fix the option handling for '--', and added it to the help text.
>
>
> -Phil

On Mon, Mar 4, 2019 at 1:34 PM Phil Sainty <psainty@orcon.net.nz> wrote:
>
> 5/03/19 5:23 AM, Kenneth Cochran wrote:
> > Adding Phil for comments
>
> Thank you for following this up, Kenneth.  I'll do some testing with
> your patch sometime soon.
>
> I've realised that the last version of my script that I posted to the
> mailing list was buggy, and that in wanting to hold off sending another
> version for a little while in case I found more bugs, I in fact failed
> to send a fixed version at all.
>
> This is probably not relevant to your patches; but just in case,
> the up to date code for that script is here:
>
> https://stackoverflow.com/a/23532744/324105
>
> and the fixes since v1.11 were:
>
> * Change incorrect uses of git show-ref, introduced by v1.10 (including
>   effective regression of v1.08), to use git symbolic-ref instead.
>
> * Fix the option handling for '--', and added it to the help text.
>
>
> -Phil

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [RFC PATCH 0/4] Add alias option to git branch
  2019-03-04 15:45 [RFC PATCH 0/4] Add alias option to git branch Kenneth Cochran
  2019-03-04 15:47 ` [RFC PATCH 1/4] " Kenneth Cochran
@ 2019-03-05 13:21 ` Junio C Hamano
  2019-03-05 17:36   ` Kenneth Cochran
  1 sibling, 1 reply; 11+ messages in thread
From: Junio C Hamano @ 2019-03-05 13:21 UTC (permalink / raw)
  To: Kenneth Cochran; +Cc: git, Sahil Dua, Duy Nguyen, Jeff King

Kenneth Cochran <kenneth.cochran101@gmail.com> writes:

> From c1bad54b29ae1c1d8548d248f6ecaa5959e55f7b Mon Sep 17 00:00:00 2001
> From: Kenneth Cochran <kenneth.cochran101@gmail.com>
> Date: Mon, 4 Mar 2019 09:40:22 -0600
> Subject: [RFC PATCH 0/4] Add alias option to git branch
> Cc: Sahil Dua <sahildua2305@gmail.com>,
>     Duy Nguyen <pclouds@gmail.com>,
>     Jeff King <peff@peff.net>

Avoid using these in-body headers.

Reader's MUA won't show this "Subject:", but instead show the same
"Add alias option to gir branch", among hundreds of mailing list
messages, making it very tempting to ignore these four messages.


> I find myself often using git symbolic-ref to get around work requirements to use branch names that are not very human friendly.
> There are a few problems with this:
> 	- There’s a lot of text to type
> 	- Mistyping certain parts (heads/refs) will do things other than create a branch alias
> 	- It will happily overwrite an existing branch
> 	- Deleting one that is checked out will put HEAD in an invalid state.

Meh.

All of the above are problems _you_ create by trying to use symbolic
refs.  If the project wants to use an overlong branch name, using it
with "git branch" or "git checkout" or whatever would be a much
better solution.  Command-line completion will complete long branch
names, and "git branch overly-long-name-of-an-existing-branch" will
not overwrite an existing branch (without --force).  "git branch -d
overly-long-name-of-an-existing-branch" would not delete an
checked-out branch, either.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [RFC PATCH 0/4] Add alias option to git branch
  2019-03-05 13:21 ` [RFC PATCH 0/4] " Junio C Hamano
@ 2019-03-05 17:36   ` Kenneth Cochran
  2019-03-06 10:13     ` Phil Sainty
  0 siblings, 1 reply; 11+ messages in thread
From: Kenneth Cochran @ 2019-03-05 17:36 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Sahil Dua, Duy Nguyen, Jeff King, Phil Sainty

On Tue, Mar 5, 2019 at 7:21 AM Junio C Hamano <gitster@pobox.com> wrote:
>
> Kenneth Cochran <kenneth.cochran101@gmail.com> writes:
>
> > From c1bad54b29ae1c1d8548d248f6ecaa5959e55f7b Mon Sep 17 00:00:00 2001
> > From: Kenneth Cochran <kenneth.cochran101@gmail.com>
> > Date: Mon, 4 Mar 2019 09:40:22 -0600
> > Subject: [RFC PATCH 0/4] Add alias option to git branch
> > Cc: Sahil Dua <sahildua2305@gmail.com>,
> >     Duy Nguyen <pclouds@gmail.com>,
> >     Jeff King <peff@peff.net>
>
> Avoid using these in-body headers.
>
> Reader's MUA won't show this "Subject:", but instead show the same
> "Add alias option to gir branch", among hundreds of mailing list
> messages, making it very tempting to ignore these four messages.
>

Thanks, I'll be sure to fix that in the future.

>
> > I find myself often using git symbolic-ref to get around work requirements to use branch names that are not very human friendly.
> > There are a few problems with this:
> >       - There’s a lot of text to type
> >       - Mistyping certain parts (heads/refs) will do things other than create a branch alias
> >       - It will happily overwrite an existing branch
> >       - Deleting one that is checked out will put HEAD in an invalid state.
>
> Meh.
>
> All of the above are problems _you_ create by trying to use symbolic
> refs.  If the project wants to use an overlong branch name, using it
> with "git branch" or "git checkout" or whatever would be a much
> better solution.  Command-line completion will complete long branch
> names, and "git branch overly-long-name-of-an-existing-branch" will
> not overwrite an existing branch (without --force).  "git branch -d
> overly-long-name-of-an-existing-branch" would not delete an
> checked-out branch, either.
>

I definitely agree, I had only meant that these were problems with my
current solution of using git symbolic-ref directly - problems that these
patches are meant to fix. I probably should have included more
information about why I use that solution in the first place.

Command line completion definitely helps in some cases, but not all - for
example, let's say I have two branches, feature/PRODUCT-13032 and
feature/PRODUCT-13023. These branches are generally short lived, so
they're not around long enough that the numbers have much meaning to
me - even with tab completion, I need to have the bug tracking software
open alongside the terminal in order to keep them separated. This can be
even more pronounced when working on several branches that are
numbered in sequence.

`git checkout foo` is much easier than `git checkout feature/PRODUCT-13032`,
even with tab completion. There's a significant number of stack overflow
questions about this functionality, and for almost all of them,
`git symbolic-ref refs/heads/newname refs/heads/branchname` is the accepted
answer. There's definitely interest in having this ability besides just me.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [RFC PATCH 0/4] Add alias option to git branch
  2019-03-05 17:36   ` Kenneth Cochran
@ 2019-03-06 10:13     ` Phil Sainty
  0 siblings, 0 replies; 11+ messages in thread
From: Phil Sainty @ 2019-03-06 10:13 UTC (permalink / raw)
  To: Kenneth Cochran, Junio C Hamano; +Cc: git, Sahil Dua, Duy Nguyen, Jeff King

I can only concur about the genuine usefulness of symbolic refs as
branch aliases.  I wrote my shell script for this 5 years ago, and
I've made use of the facility almost every working day since.

I jump around branches frequently, and my feature branch names always
start with an issue/bug number followed by a short description -- which
is perfect for listings and seeing at a glance what a branch is about,
and terrible for tab-completion.

Those long branch names are useful and informative for the developers
on the project, but being able to also have a 2-3 letter alias in my
working copy for the lifetime of a branch -- something which is trivial
for me to remember and type -- gives me the best of both worlds, and
I find it to be a tremendous convenience.

It's really not dissimilar to why so many people find shell aliases
to be so handy.

The nice thing is that all the plumbing is already there and working.
I've used it happily for 5 years, and other people use it similarly.
This feature just adds some protective porcelain over it, so that
people can more easily make use of the existing benefits without any
of the potential dangers.


-Phil

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2019-03-06 10:13 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-04 15:45 [RFC PATCH 0/4] Add alias option to git branch Kenneth Cochran
2019-03-04 15:47 ` [RFC PATCH 1/4] " Kenneth Cochran
2019-03-04 15:48   ` [RFC PATCH 2/4] " Kenneth Cochran
2019-03-04 15:49     ` [RFC PATCH 3/4] " Kenneth Cochran
2019-03-04 15:49       ` [RFC PATCH 4/4] " Kenneth Cochran
2019-03-04 16:38         ` Kenneth Cochran
     [not found]         ` <CAJ145vUChd7+5QkmJsOK3bzZsudWfzZYp5wHZDzoq8SKSv0g0A@mail.gmail.com>
2019-03-04 19:33           ` Phil Sainty
2019-03-04 19:52             ` Kenneth Cochran
2019-03-05 13:21 ` [RFC PATCH 0/4] " Junio C Hamano
2019-03-05 17:36   ` Kenneth Cochran
2019-03-06 10:13     ` Phil Sainty

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).