Skip to contentSkip to conversation

transport-helper: updates

PATCH Superseded Felipe Contreras 4 participants 20 messages Jun 15, 2016 Documentation

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v4 cover transport-helper: updates

Hi,

Here are the patches that allow transport helpers to be completely transparent; renaming branches, deleting them, custom refspecs, --force, --dry-run, reporting forced update, everything works.

Some of these were were sent before and rejected without a reason, but here they are again in case anybody is interested.

This time rebased on top of the latest master, plus a few fixes.

Diff from v3:

builtin/fast-export.c +1 -1
index 9b728ca..60d4c80 100644
@@ -686,7 +686,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
        struct commit *commit;
        char *export_filename = NULL, *import_filename = NULL;
        uint32_t lastimportid;
-       struct string_list refspecs_list;
+       struct string_list refspecs_list = STRING_LIST_INIT_NODUP;
        struct option options[] = {
                OPT_INTEGER(0, "progress", &progress,
                            N_("show progress after <n> objects")),
transport-helper.c +0 -3
index d94eaf4..91636d5 100644
@@ -836,9 +836,6 @@ static int push_refs_with_export(struct transport *transport,
                char *private;
                unsigned char sha1[20];
 
-               if (ref->deletion)
-                       die("remote-helpers do not support ref deletion");
-
                private = apply_refspecs(data->refspecs, data->refspec_nr, ref->name);
                if (private && !get_sha1(private, sha1)) {
                        strbuf_addf(&buf, "^%s", private);

Felipe Contreras (10):
transport-helper: add 'force' to 'export' helpers
transport-helper: fix extra lines
transport-helper: check for 'forced update' message
fast-export: improve argument parsing
fast-export: add new --refspec option
transport-helper: add support for old:new refspec
fast-import: add support to delete refs
fast-export: add support to delete refs
transport-helper: add support to delete branches
transport-helper: don't update refs in dry-run

 Documentation/git-fast-export.txt |  4 ++++
 Documentation/git-fast-import.txt |  3 +++
 builtin/fast-export.c             | 47 ++++++++++++++++++++++++++++++++++++++-
 fast-import.c                     | 13 ++++++++---
 t/t5801-remote-helpers.sh         | 10 ++++++++-
 t/t9300-fast-import.sh            | 18 +++++++++++++++
 t/t9350-fast-export.sh            | 18 +++++++++++++++
 transport-helper.c                | 47 ++++++++++++++++++++++++++-------------
 8 files changed, 140 insertions(+), 20 deletions(-)
Signature · 1 line
1.8.4-fc
#1 lore raw

PATCH v4 1/10 transport-helper: add 'force' to 'export' helpers

Otherwise they cannot know when to force the push or not (other than hacks).

---
 transport-helper.c | 5 +++++
 1 file changed, 5 insertions(+)
transport-helper.c +5 -0
index b32e2d6..408d596 100644
@@ -853,6 +853,11 @@ static int push_refs_with_export(struct transport *transport,
 			die("helper %s does not support dry-run", data->name);
 	}
 
+	if (flags & TRANSPORT_PUSH_FORCE) {
+		if (set_helper_option(transport, "force", "true") != 0)
+			die("helper %s does not support 'force'", data->name);
+	}
+
 	helper = get_helper(transport);
 
 	write_constant(helper->in, "export\n");
Signature · 1 line
1.8.4-fc
#2 lore raw

[PATCH v4 11/10] fixup! transport-helper: add 'force' to 'export' helpers

document the new 'force' option

---
 Documentation/gitremote-helpers.txt | 4 ++++
 1 file changed, 4 insertions(+)
Documentation/gitremote-helpers.txt +4 -0
index f1f4ca9..e75699c 100644
@@ -437,6 +437,10 @@ set by Git if the remote helper has the 'option' capability.
 'option check-connectivity' \{'true'|'false'\}::
 	Request the helper to check connectivity of a clone.
 
+'option force' \{'true'|'false'\}::
+	Request the helper to perform a force update.  Defaults to
+	'false'.
+
 SEE ALSO
 --------
 linkgit:git-remote[1]
Signature · 1 line
1.8.4.1.610.g2fe5c0e
#3 lore raw

PATCH v4 2/10 transport-helper: fix extra lines

In reply to Felipe Contreras

Commit 9c51558 (transport-helper: trivial code shuffle) moved these lines above, but 99d9ec0 (Merge branch 'fc/transport-helper-no-refspec') had a wrong merge conflict and readded them.

---
 transport-helper.c | 3 ---
 1 file changed, 3 deletions(-)
transport-helper.c +0 -3
index 408d596..707351d 100644
@@ -879,9 +879,6 @@ static int push_refs_with_export(struct transport *transport,
 		}
 		free(private);
 
-		if (ref->deletion)
-			die("remote-helpers do not support ref deletion");
-
 		if (ref->peer_ref) {
 			if (strcmp(ref->peer_ref->name, ref->name))
 				die("remote-helpers do not support old:new syntax");
Signature · 1 line
1.8.4-fc
#4 lore raw

PATCH v4 3/10 transport-helper: check for 'forced update' message

In reply to Felipe Contreras

So the remote-helpers can tell us when a forced push was needed.

---
 transport-helper.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
transport-helper.c +7 -1
index 707351d..f8eb143 100644
@@ -643,7 +643,7 @@ static int push_update_ref_status(struct strbuf *buf,
 				   struct ref *remote_refs)
 {
 	char *refname, *msg;
-	int status;
+	int status, forced = 0;
 
 	if (!prefixcmp(buf->buf, "ok ")) {
 		status = REF_STATUS_OK;
@@ -701,6 +701,11 @@ static int push_update_ref_status(struct strbuf *buf,
 			free(msg);
 			msg = NULL;
 		}
+		else if (!strcmp(msg, "forced update")) {
+			forced = 1;
+			free(msg);
+			msg = NULL;
+		}
 	}
 
 	if (*ref)
@@ -722,6 +727,7 @@ static int push_update_ref_status(struct strbuf *buf,
 	}
 
 	(*ref)->status = status;
+	(*ref)->forced_update = forced;
 	(*ref)->remote_status = msg;
 	return !(status == REF_STATUS_OK);
 }
Signature · 1 line
1.8.4-fc
#5 lore raw

PATCH v4 4/10 fast-export: improve argument parsing

In reply to Felipe Contreras

We don't want to pass arguments specific to fast-export to setup_revisions.

---
 builtin/fast-export.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
builtin/fast-export.c +2 -1
index 78250ea..eea5b8c 100644
@@ -701,8 +701,9 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
 	revs.topo_order = 1;
 	revs.show_source = 1;
 	revs.rewrite_parents = 1;
+	argc = parse_options(argc, argv, prefix, options, fast_export_usage,
+			PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN);
 	argc = setup_revisions(argc, argv, &revs, NULL);
-	argc = parse_options(argc, argv, prefix, options, fast_export_usage, 0);
 	if (argc > 1)
 		usage_with_options (fast_export_usage, options);
 
Signature · 1 line
1.8.4-fc
#6 lore raw

PATCH v4 5/10 fast-export: add new --refspec option

In reply to Felipe Contreras

So that we can convert the exported ref names.

---
 Documentation/git-fast-export.txt |  4 ++++
 builtin/fast-export.c             | 30 ++++++++++++++++++++++++++++++
 t/t9350-fast-export.sh            |  7 +++++++
 3 files changed, 41 insertions(+)
Documentation/git-fast-export.txt +4 -0
index 85f1f30..221506b 100644
@@ -105,6 +105,10 @@ marks the same across runs.
 	in the commit (as opposed to just listing the files which are
 	different from the commit's first parent).
 
+--refspec::
+	Apply the specified refspec to each ref exported. Multiple of them can
+	be specified.
+
 [<git-rev-list-args>...]::
 	A list of arguments, acceptable to 'git rev-parse' and
 	'git rev-list', that specifies the specific objects and references
builtin/fast-export.c +30 -0
index eea5b8c..b6f623e 100644
@@ -17,6 +17,7 @@
 #include "utf8.h"
 #include "parse-options.h"
 #include "quote.h"
+#include "remote.h"
 
 static const char *fast_export_usage[] = {
 	N_("git fast-export [rev-list-opts]"),
@@ -31,6 +32,8 @@ static int use_done_feature;
 static int no_data;
 static int full_tree;
 static struct string_list extra_refs = STRING_LIST_INIT_NODUP;
+static struct refspec *refspecs;
+static int refspecs_nr;
 
 static int parse_opt_signed_tag_mode(const struct option *opt,
 				     const char *arg, int unset)
@@ -525,6 +528,15 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info)
 		if (dwim_ref(e->name, strlen(e->name), sha1, &full_name) != 1)
 			continue;
 
+		if (refspecs) {
+			char *private;
+			private = apply_refspecs(refspecs, refspecs_nr, full_name);
+			if (private) {
+				free(full_name);
+				full_name = private;
+			}
+		}
+
 		commit = get_commit(e, full_name);
 		if (!commit) {
 			warning("%s: Unexpected object of type %s, skipping.",
@@ -668,6 +680,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
 	struct commit *commit;
 	char *export_filename = NULL, *import_filename = NULL;
 	uint32_t lastimportid;
+	struct string_list refspecs_list = STRING_LIST_INIT_NODUP;
 	struct option options[] = {
 		OPT_INTEGER(0, "progress", &progress,
 			    N_("show progress after <n> objects")),
@@ -688,6 +701,8 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
 		OPT_BOOL(0, "use-done-feature", &use_done_feature,
 			     N_("Use the done feature to terminate the stream")),
 		OPT_BOOL(0, "no-data", &no_data, N_("Skip output of blob data")),
+		OPT_STRING_LIST(0, "refspec", &refspecs_list, N_("refspec"),
+			     N_("Apply refspec to exported refs")),
 		OPT_END()
 	};
 
@@ -707,6 +722,19 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
 	if (argc > 1)
 		usage_with_options (fast_export_usage, options);
 
+	if (refspecs_list.nr) {
+		const char *refspecs_str[refspecs_list.nr];
+		int i;
+
+		for (i = 0; i < refspecs_list.nr; i++)
+			refspecs_str[i] = refspecs_list.items[i].string;
+
+		refspecs_nr = refspecs_list.nr;
+		refspecs = parse_fetch_refspec(refspecs_nr, refspecs_str);
+
+		string_list_clear(&refspecs_list, 1);
+	}
+
 	if (use_done_feature)
 		printf("feature done\n");
 
@@ -741,5 +769,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
 	if (use_done_feature)
 		printf("done\n");
 
+	free_refspec(refspecs_nr, refspecs);
+
 	return 0;
 }
t/t9350-fast-export.sh +7 -0
index 34c2d8f..dc6666f 100755
@@ -504,4 +504,11 @@ test_expect_success 'refs are updated even if no commits need to be exported' '
 	test_cmp expected actual
 '
 
+test_expect_success 'use refspec' '
+	git fast-export --refspec refs/heads/master:refs/heads/foobar master | \
+		grep "^commit " | sort | uniq > actual &&
+	echo "commit refs/heads/foobar" > expected &&
+	test_cmp expected actual
+'
+
 test_done
Signature · 1 line
1.8.4-fc
#7 lore raw

PATCH v4 6/10 transport-helper: add support for old:new refspec

In reply to Felipe Contreras

By using fast-export's new --refspec option.

---
 t/t5801-remote-helpers.sh |  2 +-
 transport-helper.c        | 13 ++++++++++---
 2 files changed, 11 insertions(+), 4 deletions(-)
t/t5801-remote-helpers.sh +1 -1
index 613f69a..407c18d 100755
@@ -87,7 +87,7 @@ test_expect_success 'push new branch by name' '
 	compare_refs local HEAD server refs/heads/new-name
 '
 
-test_expect_failure 'push new branch with old:new refspec' '
+test_expect_success 'push new branch with old:new refspec' '
 	(cd local &&
 	 git push origin new-name:new-refspec
 	) &&
transport-helper.c +10 -3
index f8eb143..5454822 100644
@@ -848,7 +848,7 @@ static int push_refs_with_export(struct transport *transport,
 	struct ref *ref;
 	struct child_process *helper, exporter;
 	struct helper_data *data = transport->data;
-	struct string_list revlist_args = STRING_LIST_INIT_NODUP;
+	struct string_list revlist_args = STRING_LIST_INIT_DUP;
 	struct strbuf buf = STRBUF_INIT;
 
 	if (!data->refspecs)
@@ -886,8 +886,13 @@ static int push_refs_with_export(struct transport *transport,
 		free(private);
 
 		if (ref->peer_ref) {
-			if (strcmp(ref->peer_ref->name, ref->name))
-				die("remote-helpers do not support old:new syntax");
+			if (strcmp(ref->name, ref->peer_ref->name)) {
+				struct strbuf buf = STRBUF_INIT;
+				strbuf_addf(&buf, "%s:%s", ref->peer_ref->name, ref->name);
+				string_list_append(&revlist_args, "--refspec");
+				string_list_append(&revlist_args, buf.buf);
+				strbuf_release(&buf);
+			}
 			string_list_append(&revlist_args, ref->peer_ref->name);
 		}
 	}
@@ -895,6 +900,8 @@ static int push_refs_with_export(struct transport *transport,
 	if (get_exporter(transport, &exporter, &revlist_args))
 		die("Couldn't run fast-export");
 
+	string_list_clear(&revlist_args, 1);
+
 	if (finish_command(&exporter))
 		die("Error while running fast-export");
 	push_update_refs_status(data, remote_refs);
Signature · 1 line
1.8.4-fc
#8 lore raw

PATCH v4 7/10 fast-import: add support to delete refs

In reply to Felipe Contreras
---
 Documentation/git-fast-import.txt |  3 +++
 fast-import.c                     | 13 ++++++++++---
 t/t9300-fast-import.sh            | 18 ++++++++++++++++++
 3 files changed, 31 insertions(+), 3 deletions(-)
Documentation/git-fast-import.txt +3 -0
index 73f9806..c49ede4 100644
@@ -483,6 +483,9 @@ Marks must be declared (via `mark`) before they can be used.
 * Any valid Git SHA-1 expression that resolves to a commit.  See
   ``SPECIFYING REVISIONS'' in linkgit:gitrevisions[7] for details.
 
+* The special null SHA-1 (40 zeros) specifices that the branch is to be
+  removed.
+
 The special case of restarting an incremental import from the
 current branch value should be written as:
 ----
fast-import.c +10 -3
index f4d9969..fdce0b7 100644
@@ -248,6 +248,7 @@ struct branch {
 	uintmax_t last_commit;
 	uintmax_t num_notes;
 	unsigned active : 1;
+	unsigned delete : 1;
 	unsigned pack_id : PACK_ID_BITS;
 	unsigned char sha1[20];
 };
@@ -1690,10 +1691,13 @@ static int update_branch(struct branch *b)
 	struct ref_lock *lock;
 	unsigned char old_sha1[20];
 
-	if (is_null_sha1(b->sha1))
-		return 0;
 	if (read_ref(b->name, old_sha1))
 		hashclr(old_sha1);
+	if (is_null_sha1(b->sha1)) {
+		if (b->delete)
+			delete_ref(b->name, old_sha1, 0);
+		return 0;
+	}
 	lock = lock_any_ref_for_update(b->name, old_sha1, 0, NULL);
 	if (!lock)
 		return error("Unable to lock %s", b->name);
@@ -2620,8 +2624,11 @@ static int parse_from(struct branch *b)
 			free(buf);
 		} else
 			parse_from_existing(b);
-	} else if (!get_sha1(from, b->sha1))
+	} else if (!get_sha1(from, b->sha1)) {
 		parse_from_existing(b);
+		if (is_null_sha1(b->sha1))
+			b->delete = 1;
+	}
 	else
 		die("Invalid ref name or SHA1 expression: %s", from);
 
t/t9300-fast-import.sh +18 -0
index 88fc407..f453388 100755
@@ -2999,4 +2999,22 @@ test_expect_success 'T: ls root tree' '
 	test_cmp expect actual
 '
 
+test_expect_success 'T: delete branch' '
+	git branch to-delete &&
+	git fast-import <<-EOF &&
+	reset refs/heads/to-delete
+	from 0000000000000000000000000000000000000000
+	EOF
+	test_must_fail git rev-parse --verify refs/heads/to-delete
+'
+
+test_expect_success 'T: empty reset doesnt delete branch' '
+	git branch not-to-delete &&
+	git fast-import <<-EOF &&
+	reset refs/heads/not-to-delete
+	EOF
+	git show-ref &&
+	git rev-parse --verify refs/heads/not-to-delete
+'
+
 test_done
Signature · 1 line
1.8.4-fc
#9 lore raw

Re: [PATCH v4 07/10] fast-import: add support to delete refs

Quoted 12 lines · Felipe Contreras
---
 Documentation/git-fast-import.txt |  3 +++
 fast-import.c                     | 13 ++++++++++---
 t/t9300-fast-import.sh            | 18 ++++++++++++++++++
 3 files changed, 31 insertions(+), 3 deletions(-)
Documentation/git-fast-import.txt +0 -0
index 73f9806..c49ede4 100644

Documentation/git-fast-import.txt Marks must be declared (via `mark`) before they can be used. · line 486

Quoted 4 lines
Documentation/git-fast-import.txt +1 -0
@@ -483,6 +483,9 @@ Marks must be declared (via `mark`) before they can be used.
 * Any valid Git SHA-1 expression that resolves to a commit.  See
   ``SPECIFYING REVISIONS'' in linkgit:gitrevisions[7] for details.
 
+* The special null SHA-1 (40 zeros) specifices that the branch is to be

s/specifices/specifies/

Quoted 5 lines
Documentation/git-fast-import.txt +2 -0
+  removed.
+
 The special case of restarting an incremental import from the
 current branch value should be written as:
 ----
#10 lore raw

PATCH v4 8/10 fast-export: add support to delete refs

In reply to Felipe Contreras
---
 builtin/fast-export.c  | 14 ++++++++++++++
 t/t9350-fast-export.sh | 11 +++++++++++
 2 files changed, 25 insertions(+)
builtin/fast-export.c +14 -0
index b6f623e..8ed41b4 100644
@@ -673,6 +673,19 @@ static void import_marks(char *input_file)
 	fclose(f);
 }
 
+static void handle_deletes(void)
+{
+	int i;
+	for (i = 0; i < refspecs_nr; i++) {
+		struct refspec *refspec = &refspecs[i];
+		if (*refspec->src)
+			continue;
+
+		printf("reset %s\nfrom %s\n\n",
+				refspec->dst, sha1_to_hex(null_sha1));
+	}
+}
+
 int cmd_fast_export(int argc, const char **argv, const char *prefix)
 {
 	struct rev_info revs;
@@ -762,6 +775,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
 	}
 
 	handle_tags_and_duplicates();
+	handle_deletes();
 
 	if (export_filename && lastimportid != last_idnum)
 		export_marks(export_filename);
t/t9350-fast-export.sh +11 -0
index dc6666f..ea6c96c 100755
@@ -511,4 +511,15 @@ test_expect_success 'use refspec' '
 	test_cmp expected actual
 '
 
+test_expect_success 'delete refspec' '
+	git branch to-delete &&
+	git fast-export --refspec :refs/heads/to-delete to-delete ^to-delete > actual &&
+	cat > expected <<-EOF &&
+	reset refs/heads/to-delete
+	from 0000000000000000000000000000000000000000
+
+	EOF
+	test_cmp expected actual
+'
+
 test_done
Signature · 1 line
1.8.4-fc
#11 lore raw

PATCH v4 9/10 transport-helper: add support to delete branches

In reply to Felipe Contreras

For remote-helpers that use 'export' to push.

---
 t/t5801-remote-helpers.sh |  8 ++++++++
 transport-helper.c        | 11 ++++++-----
 2 files changed, 14 insertions(+), 5 deletions(-)
t/t5801-remote-helpers.sh +8 -0
index 407c18d..be543c0 100755
@@ -94,6 +94,14 @@ test_expect_success 'push new branch with old:new refspec' '
 	compare_refs local HEAD server refs/heads/new-refspec
 '
 
+test_expect_success 'push delete branch' '
+	(cd local &&
+	 git push origin :new-name
+	) &&
+	test_must_fail git --git-dir="server/.git" \
+	 rev-parse --verify refs/heads/new-name
+'
+
 test_expect_success 'cloning without refspec' '
 	GIT_REMOTE_TESTGIT_REFSPEC="" \
 	git clone "testgit::${PWD}/server" local2 2>error &&
transport-helper.c +6 -5
index 5454822..4f47bdd 100644
@@ -874,9 +874,6 @@ static int push_refs_with_export(struct transport *transport,
 		char *private;
 		unsigned char sha1[20];
 
-		if (ref->deletion)
-			die("remote-helpers do not support ref deletion");
-
 		private = apply_refspecs(data->refspecs, data->refspec_nr, ref->name);
 		if (private && !get_sha1(private, sha1)) {
 			strbuf_addf(&buf, "^%s", private);
@@ -888,12 +885,16 @@ static int push_refs_with_export(struct transport *transport,
 		if (ref->peer_ref) {
 			if (strcmp(ref->name, ref->peer_ref->name)) {
 				struct strbuf buf = STRBUF_INIT;
-				strbuf_addf(&buf, "%s:%s", ref->peer_ref->name, ref->name);
+				if (!ref->deletion)
+					strbuf_addf(&buf, "%s:%s", ref->peer_ref->name, ref->name);
+				else
+					strbuf_addf(&buf, ":%s", ref->name);
 				string_list_append(&revlist_args, "--refspec");
 				string_list_append(&revlist_args, buf.buf);
 				strbuf_release(&buf);
 			}
-			string_list_append(&revlist_args, ref->peer_ref->name);
+			if (!ref->deletion)
+				string_list_append(&revlist_args, ref->peer_ref->name);
 		}
 	}
 
Signature · 1 line
1.8.4-fc
#12 lore raw

PATCH v4 10/10 transport-helper: don't update refs in dry-run

In reply to Felipe Contreras

The remote helper namespace should not be updated.

---
 transport-helper.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
transport-helper.c +5 -4
index 4f47bdd..ef91882 100644
@@ -733,7 +733,8 @@ static int push_update_ref_status(struct strbuf *buf,
 }
 
 static void push_update_refs_status(struct helper_data *data,
-				    struct ref *remote_refs)
+				    struct ref *remote_refs,
+				    int flags)
 {
 	struct strbuf buf = STRBUF_INIT;
 	struct ref *ref = remote_refs;
@@ -747,7 +748,7 @@ static void push_update_refs_status(struct helper_data *data,
 		if (push_update_ref_status(&buf, &ref, remote_refs))
 			continue;
 
-		if (!data->refspecs || data->no_private_update)
+		if (flags & TRANSPORT_PUSH_DRY_RUN || !data->refspecs || data->no_private_update)
 			continue;
 
 		/* propagate back the update to the remote namespace */
@@ -838,7 +839,7 @@ static int push_refs_with_push(struct transport *transport,
 	sendline(data, &buf);
 	strbuf_release(&buf);
 
-	push_update_refs_status(data, remote_refs);
+	push_update_refs_status(data, remote_refs, flags);
 	return 0;
 }
 
@@ -905,7 +906,7 @@ static int push_refs_with_export(struct transport *transport,
 
 	if (finish_command(&exporter))
 		die("Error while running fast-export");
-	push_update_refs_status(data, remote_refs);
+	push_update_refs_status(data, remote_refs, flags);
 	return 0;
 }
 
Signature · 1 line
1.8.4-fc
#13 lore raw

[PATCH v4 12/10] git-remote-testgit: support the new 'force' option

In reply to Felipe Contreras
---
 git-remote-testgit.sh | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
git-remote-testgit.sh +18 -0
index 6d2f282..80546c1 100755
@@ -6,6 +6,7 @@ url=$2
 
 dir="$GIT_DIR/testgit/$alias"
 prefix="refs/testgit/$alias"
+forcearg=
 
 default_refspec="refs/heads/*:${prefix}/heads/*"
 
@@ -39,6 +40,7 @@ do
 		fi
 		test -n "$GIT_REMOTE_TESTGIT_SIGNED_TAGS" && echo "signed-tags"
 		test -n "$GIT_REMOTE_TESTGIT_NO_PRIVATE_UPDATE" && echo "no-private-update"
+		echo 'option'
 		echo
 		;;
 	list)
@@ -93,6 +95,7 @@ do
 		before=$(git for-each-ref --format=' %(refname) %(objectname) ')
 
 		git fast-import \
+			${forcearg} \
 			${testgitmarks:+"--import-marks=$testgitmarks"} \
 			${testgitmarks:+"--export-marks=$testgitmarks"} \
 			--quiet
@@ -115,6 +118,21 @@ do
 
 		echo
 		;;
+	option\ *)
+		read cmd opt val <<EOF
+${line}
+EOF
+		case ${opt} in
+		    force)
+			case ${val} in
+			    true) forcearg=--force; echo 'ok';;
+			    false) forcearg=; echo 'ok';;
+			    *) printf %s\\n "error '${val}'\
+ is not a valid value for option ${opt}";;
+			esac;;
+		    *) echo "unsupported";;
+		esac
+		;;
 	'')
 		exit
 		;;
Signature · 1 line
1.8.4.1.614.ga09cf56
#14 lore raw

[PATCH v4 13/10] test: remote-helper: add test for force pushes

---
 t/t5801-remote-helpers.sh | 13 +++++++++++++
 1 file changed, 13 insertions(+)
t/t5801-remote-helpers.sh +13 -0
index be543c0..93a7d34 100755
@@ -102,6 +102,19 @@ test_expect_success 'push delete branch' '
 	 rev-parse --verify refs/heads/new-name
 '
 
+test_expect_success 'force push' '
+	(cd local &&
+	 git checkout -b force-test &&
+	 echo content >>file &&
+	 git commit -a -m eight &&
+	 git push origin force-test &&
+	 echo content >>file &&
+	 git commit -a --amend -m eight-modified &&
+	 git push --force origin force-test
+	) &&
+	compare_refs local refs/heads/force-test server refs/heads/force-test
+'
+
 test_expect_success 'cloning without refspec' '
 	GIT_REMOTE_TESTGIT_REFSPEC="" \
 	git clone "testgit::${PWD}/server" local2 2>error &&
Signature · 1 line
1.8.4.1.614.ga09cf56
#15 lore raw

RE: [PATCH v4 12/10] git-remote-testgit: support the new 'force' option

In reply to Richard Hansen
Quoted 34 lines · Richard Hansen
---
 git-remote-testgit.sh | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
git-remote-testgit.sh +3 -0
index 6d2f282..80546c1 100755
@@ -6,6 +6,7 @@ url=$2
 
 dir="$GIT_DIR/testgit/$alias"
 prefix="refs/testgit/$alias"
+forcearg=
 
 default_refspec="refs/heads/*:${prefix}/heads/*"
 
@@ -39,6 +40,7 @@ do
 		fi
 		test -n "$GIT_REMOTE_TESTGIT_SIGNED_TAGS" && echo "signed-tags"
 		test -n "$GIT_REMOTE_TESTGIT_NO_PRIVATE_UPDATE" && echo "no-private-update"
+		echo 'option'
 		echo
 		;;
 	list)
@@ -93,6 +95,7 @@ do
 		before=$(git for-each-ref --format=' %(refname) %(objectname) ')
 
 		git fast-import \
+			${forcearg} \
 			${testgitmarks:+"--import-marks=$testgitmarks"} \
 			${testgitmarks:+"--export-marks=$testgitmarks"} \
 			--quiet

git-remote-testgit.sh do · line 124

Quoted 7 lines
git-remote-testgit.sh +4 -0
@@ -115,6 +118,21 @@ do
 
 		echo
 		;;
+	option\ *)
+		read cmd opt val <<EOF
+${line}
+EOF

We can do <<-EOF to align this properly.

Also, I don't see why all the variables are ${foo} instead of $foo.

git-remote-testgit.sh do · line 126

Quoted 2 lines
git-remote-testgit.sh +2 -0
+		case ${opt} in
+		    force)

I think the convention is to align these:

case $opt in
force)

git-remote-testgit.sh do · line 131

Quoted 5 lines
git-remote-testgit.sh +5 -0
+			case ${val} in
+			    true) forcearg=--force; echo 'ok';;
+			    false) forcearg=; echo 'ok';;
+			    *) printf %s\\n "error '${val}'\
+ is not a valid value for option ${opt}";;

I think this is packing a lot of stuff and it's not that readable.

Moreover, this is not for production purposes, it's for testing purposes and a guideline, I think this suffices.

	option\ *)
		read cmd opt val <<-EOF
		$line
		EOF
		case $opt in
		force)
			test $val = "true" && force="true" || force=
			echo "ok"
			;;
		*)
			echo "unsupported"
			;;
		esac
		;;

But this is definetly good to have, will merge.

Signature · 1 line
Felipe Contreras
#16 lore raw

Re: [PATCH v4 12/10] git-remote-testgit: support the new 'force' option

Quoted 36 lines · Felipe Contreras
Quoted 35 lines · Richard Hansen
---
 git-remote-testgit.sh | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
git-remote-testgit.sh +3 -0
index 6d2f282..80546c1 100755
@@ -6,6 +6,7 @@ url=$2
 
 dir="$GIT_DIR/testgit/$alias"
 prefix="refs/testgit/$alias"
+forcearg=
 
 default_refspec="refs/heads/*:${prefix}/heads/*"
 
@@ -39,6 +40,7 @@ do
 		fi
 		test -n "$GIT_REMOTE_TESTGIT_SIGNED_TAGS" && echo "signed-tags"
 		test -n "$GIT_REMOTE_TESTGIT_NO_PRIVATE_UPDATE" && echo "no-private-update"
+		echo 'option'
 		echo
 		;;
 	list)
@@ -93,6 +95,7 @@ do
 		before=$(git for-each-ref --format=' %(refname) %(objectname) ')
 
 		git fast-import \
+			${forcearg} \
 			${testgitmarks:+"--import-marks=$testgitmarks"} \
 			${testgitmarks:+"--export-marks=$testgitmarks"} \
 			--quiet
@@ -115,6 +118,21 @@ do
 
Quoted 8 lines

git-remote-testgit.sh do · line 124

Quoted 6 lines
git-remote-testgit.sh +4 -0
 		echo
 		;;
+	option\ *)
+		read cmd opt val <<EOF
+${line}
+EOF

We can do <<-EOF to align this properly.

Good point. I personally avoid tabs whenever possible, and <<- only works with tabs, so I'm in the habit of doing <<EOF.

Quoted 2 lines

Also, I don't see why all the variables are ${foo} instead of $foo.

I'm in the habit of doing ${foo} because I like the consistency -- sometimes you need them to disambiguate, and sometimes you need special expansions like ${foo##bar} or ${foo:-bar}.

In this case it's actually less consistent to do ${foo} because the rest of the file doesn't use {} when not needed, so I agree with your change.

Quoted 8 lines

git-remote-testgit.sh do · line 126

Quoted 3 lines
git-remote-testgit.sh +2 -0
+		case ${opt} in
+		    force)

I think the convention is to align these:

case $opt in
force)

The existing case statement in this file indents the patterns the same amount as the case statement, so this should be aligned to match.

In general I rarely see the case patterns indented at the same level as the case statement, possibly because Emacs shell-mode indents the patterns more than the case statement (by default). The POSIX spec contains a mix of styles:
* the normative text documenting the format of a 'case' construct indents the patterns more than the 'case' statement
* two of the four non-normative examples indent the patterns more than the 'case' statements; the other two do not

Quoted 13 lines

git-remote-testgit.sh do · line 131

Quoted 6 lines
git-remote-testgit.sh +5 -0
+			case ${val} in
+			    true) forcearg=--force; echo 'ok';;
+			    false) forcearg=; echo 'ok';;
+			    *) printf %s\\n "error '${val}'\
+ is not a valid value for option ${opt}";;

I think this is packing a lot of stuff and it's not that readable.

Moreover, this is not for production purposes, it's for testing purposes and a guideline, I think this suffices.

Quoted 14 lines
	option\ *)
		read cmd opt val <<-EOF
		$line
		EOF
		case $opt in
		force)
			test $val = "true" && force="true" || force=
			echo "ok"
			;;
		*)
			echo "unsupported"
			;;
		esac
		;;

Works for me.

Quoted 2 lines

But this is definetly good to have, will merge.

Thanks,
Richard

#17 lore raw

Re: [PATCH v4 12/10] git-remote-testgit: support the new 'force' option

Quoted 46 lines · Richard Hansen
Quoted 36 lines · Felipe Contreras
Quoted 35 lines · Richard Hansen
---
 git-remote-testgit.sh | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
git-remote-testgit.sh +3 -0
index 6d2f282..80546c1 100755
@@ -6,6 +6,7 @@ url=$2
 
 dir="$GIT_DIR/testgit/$alias"
 prefix="refs/testgit/$alias"
+forcearg=
 
 default_refspec="refs/heads/*:${prefix}/heads/*"
 
@@ -39,6 +40,7 @@ do
             fi
             test -n "$GIT_REMOTE_TESTGIT_SIGNED_TAGS" && echo "signed-tags"
             test -n "$GIT_REMOTE_TESTGIT_NO_PRIVATE_UPDATE" && echo "no-private-update"
+            echo 'option'
             echo
             ;;
     list)
@@ -93,6 +95,7 @@ do
             before=$(git for-each-ref --format=' %(refname) %(objectname) ')
 
             git fast-import \
+                    ${forcearg} \
                     ${testgitmarks:+"--import-marks=$testgitmarks"} \
                     ${testgitmarks:+"--export-marks=$testgitmarks"} \
                     --quiet
@@ -115,6 +118,21 @@ do
 
Quoted 8 lines

git-remote-testgit.sh do · line 124

Quoted 6 lines
git-remote-testgit.sh +4 -0
             echo
             ;;
+    option\ *)
+            read cmd opt val <<EOF
+${line}
+EOF

We can do <<-EOF to align this properly.

Quoted 2 lines

Good point. I personally avoid tabs whenever possible, and <<- only works with tabs, so I'm in the habit of doing <<EOF.

That looks very weird to me, plus <<-EOF is often used already in git tests.

Quoted 3 lines
Quoted 1 line

Also, I don't see why all the variables are ${foo} instead of $foo.

I'm in the habit of doing ${foo} because I like the consistency --

Sure, but with the price of less readibility. If consistency was the priority, we would be doing the follwoing in C:

if (foo) {

  # single line
}

Since the if might contain multiple lines, but we don't do that, because readibility is more important than consistency. So sometimes it's with braces, sometimes without.

Quoted 11 lines
Quoted 7 lines

git-remote-testgit.sh do · line 126

Quoted 2 lines
git-remote-testgit.sh +2 -0
+            case ${opt} in
+                force)

I think the convention is to align these:

case $opt in
force)

The existing case statement in this file indents the patterns the same amount as the case statement, so this should be aligned to match.

Quoted 8 lines

In general I rarely see the case patterns indented at the same level as the case statement, possibly because Emacs shell-mode indents the patterns more than the case statement (by default). The POSIX spec contains a mix of styles:
* the normative text documenting the format of a 'case' construct indents the patterns more than the 'case' statement
* two of the four non-normative examples indent the patterns more than the 'case' statements; the other two do not

The style in C has the cases at the same level, so I think it makes sense to do the same in shell, but I'm not sure if that's followed already.

Quoted 22 lines
Quoted 22 lines

git-remote-testgit.sh do · line 131

Quoted 5 lines
git-remote-testgit.sh +5 -0
+                    case ${val} in
+                        true) forcearg=--force; echo 'ok';;
+                        false) forcearg=; echo 'ok';;
+                        *) printf %s\\n "error '${val}'\
+ is not a valid value for option ${opt}";;

I think this is packing a lot of stuff and it's not that readable.

Moreover, this is not for production purposes, it's for testing purposes and a guideline, I think this suffices.

      option\ *)
              read cmd opt val <<-EOF
              $line
              EOF
              case $opt in
              force)
                      test $val = "true" && force="true" || force=
                      echo "ok"
                      ;;
Quoted 6 lines
Quoted 4 lines
                      echo "unsupported"
                      ;;
              esac
              ;;

Works for me.

Good, the final code style can be decided later on, and perhaps update Documentation/CodingGuidelines, but it's good the rest is more or less settled.

Cheers.

Signature · 1 line
Felipe Contreras
#18 lore raw

Re: [PATCH v4 12/10] git-remote-testgit: support the new 'force' option

In reply to Richard Hansen
Quoted 10 lines · Richard Hansen
Quoted 4 lines

I think the convention is to align these:

case $opt in
force)

The existing case statement in this file indents the patterns the same amount as the case statement, so this should be aligned to match.

In general I rarely see the case patterns indented at the same level as the case statement,

What you see does not matter in the context of this project ;-) This is what we have in Documentation/CodingGuidelines:

For shell scripts specifically (not exhaustive):

- Case arms are indented at the same depth as case and esac lines.

Thanks.

#19 lore raw

Re: [PATCH v4 12/10] git-remote-testgit: support the new 'force' option

Quoted 13 lines · Junio C Hamano
Quoted 10 lines · Richard Hansen
Quoted 4 lines

I think the convention is to align these:

case $opt in
force)

The existing case statement in this file indents the patterns the same amount as the case statement, so this should be aligned to match.

In general I rarely see the case patterns indented at the same level as the case statement,

Quoted 6 lines

What you see does not matter in the context of this project ;-) This is what we have in Documentation/CodingGuidelines:

For shell scripts specifically (not exhaustive):

- Case arms are indented at the same depth as case and esac lines.

Doh! I missed that. Thanks for pointing it out.

Thanks,
Richard