From: Vikrant Varma <vikrant.varma94@gmail.com>
To: git@vger.kernel.org
Cc: Vikrant Varma <vikrant.varma94@gmail.com>
Subject: [PATCH 1/2] help: add help_unknown_ref
Date: Wed, 1 May 2013 16:52:06 +0530 [thread overview]
Message-ID: <1367407327-5216-2-git-send-email-vikrant.varma94@gmail.com> (raw)
In-Reply-To: <1367407327-5216-1-git-send-email-vikrant.varma94@gmail.com>
Give better advice when trying to merge a branch that doesn't exist. If
the branch exists in any remotes, display a list of suggestions.
Example:
$ git merge foo
fatal: foo - not something we can merge
Did you mean this?
bar/foo
Signed-off-by: Vikrant Varma <vikrant.varma94@gmail.com>
---
help.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
help.h | 6 ++++++
2 files changed, 50 insertions(+)
diff --git a/help.c b/help.c
index 02ba043..faf18b9 100644
--- a/help.c
+++ b/help.c
@@ -7,6 +7,7 @@
#include "string-list.h"
#include "column.h"
#include "version.h"
+#include "refs.h"
void add_cmdname(struct cmdnames *cmds, const char *name, int len)
{
@@ -404,3 +405,46 @@ int cmd_version(int argc, const char **argv, const char *prefix)
printf("git version %s\n", git_version_string);
return 0;
}
+
+struct similar_ref_cb {
+ const char *base_ref;
+ struct string_list similar_refs;
+};
+
+static int append_similar_ref(const char* refname, const unsigned char *sha1, int flags, void *cb_data)
+{
+ int i;
+ struct similar_ref_cb *cb = (struct similar_ref_cb *)(cb_data);
+ for (i = strlen(refname); refname[i] != '/'; i--)
+ ;
+ /* A remote branch of the same name is deemed similar */
+ if (!prefixcmp(refname, "refs/remotes/") && !strcmp(refname + i + 1, cb->base_ref))
+ string_list_append(&(cb->similar_refs), refname + 13);
+ return 0;
+}
+
+void help_unknown_ref(const char* ref) {
+ int i;
+ struct similar_ref_cb ref_cb;
+ ref_cb.similar_refs = (struct string_list)STRING_LIST_INIT_NODUP;
+ ref_cb.base_ref = ref;
+
+ for_each_ref(append_similar_ref, &ref_cb);
+
+ fprintf_ln(stderr, _("fatal: %s - not something we can merge"), ref);
+
+ if (ref_cb.similar_refs.nr > 0) {
+ fprintf_ln(stderr,
+ Q_("\nDid you mean this?",
+ "\nDid you mean one of these?",
+ ref_cb.similar_refs.nr));
+
+ for (i = 0; i < ref_cb.similar_refs.nr; i++)
+ fprintf(stderr, "\t%s\n", ref_cb.similar_refs.items[i].string);
+ }
+ exit(1);
+}
+
+
+
+
diff --git a/help.h b/help.h
index 0ae5a12..613cb45 100644
--- a/help.h
+++ b/help.h
@@ -27,4 +27,10 @@ extern void exclude_cmds(struct cmdnames *cmds, struct cmdnames *excludes);
extern int is_in_cmdlist(struct cmdnames *cmds, const char *name);
extern void list_commands(unsigned int colopts, struct cmdnames *main_cmds, struct cmdnames *other_cmds);
+/*
+ * ref is not something that can be merged. Print a list of remote branches of the
+ * same name that the user might have meant.
+ */
+extern void help_unknown_ref(const char* ref);
+
#endif /* HELP_H */
--
1.8.3-rc0
next prev parent reply other threads:[~2013-05-01 11:24 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-01 11:22 [PATCH 0/2] Better advice on merge Vikrant Varma
2013-05-01 11:22 ` Vikrant Varma [this message]
2013-05-01 12:23 ` [PATCH 1/2] help: add help_unknown_ref Ramkumar Ramachandra
2013-05-01 14:06 ` Matthieu Moy
2013-05-01 19:55 ` Vikrant Varma
2013-05-01 20:23 ` Johannes Sixt
2013-05-01 20:32 ` Ramkumar Ramachandra
2013-05-01 21:45 ` Vikrant Varma
2013-05-01 22:12 ` Junio C Hamano
2013-05-01 18:35 ` Junio C Hamano
2013-05-01 22:26 ` Vikrant Varma
2013-05-01 23:07 ` Junio C Hamano
2013-05-01 11:22 ` [PATCH 2/2] merge: use help_unknown_ref instead of die Vikrant Varma
2013-05-01 18:36 ` Junio C Hamano
2013-05-01 18:27 ` [PATCH 0/2] Better advice on merge Jonathan Nieder
2013-05-01 23:06 ` Vikrant Varma
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=1367407327-5216-2-git-send-email-vikrant.varma94@gmail.com \
--to=vikrant.varma94@gmail.com \
--cc=git@vger.kernel.org \
/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).