Giter Site home page Giter Site logo

Comments (3)

dscho avatar dscho commented on September 23, 2024 1

Sketch of the functional change I am proposing:

diff --git a/builtin/for-each-repo.c b/builtin/for-each-repo.c
index 28186b30f548..35ab7f34ca15 100644
--- a/builtin/for-each-repo.c
+++ b/builtin/for-each-repo.c
@@ -32,6 +32,7 @@ static int run_command_on_repo(const char *path, int argc, const char ** argv)
 int cmd_for_each_repo(int argc, const char **argv, const char *prefix)
 {
 	static const char *config_key = NULL;
+	int stop_on_error = 0;
 	int i, result = 0;
 	const struct string_list *values;
 	int err;
@@ -39,6 +40,8 @@ int cmd_for_each_repo(int argc, const char **argv, const char *prefix)
 	const struct option options[] = {
 		OPT_STRING(0, "config", &config_key, N_("config"),
 			   N_("config key storing a list of repository paths")),
+		OPT_BOOL(0, "stop-on-error", &stop_on_error,
+			 N_("stop at the first repository where the operation failed")),
 		OPT_END()
 	};
 
@@ -55,8 +58,9 @@ int cmd_for_each_repo(int argc, const char **argv, const char *prefix)
 	else if (err)
 		return 0;
 
-	for (i = 0; !result && i < values->nr; i++)
-		result = run_command_on_repo(values->items[i].string, argc, argv);
+	for (i = 0; (!stop_on_error || !result) && i < values->nr; i++)
+		if (run_command_on_repo(values->items[i].string, argc, argv))
+			result = 1;
 
 	return result;
 }

from git.

dscho avatar dscho commented on September 23, 2024

The first non-existent repo stopped the loop.

This is indeed the case 😞:

https://github.com/git/git/blob/v2.43.0/builtin/for-each-repo.c#L58-L59

It would probably make sense to retain the ability to stop on the first failure, but make that an option, by default continuing (but of course still exiting with an error if the operation failed in at least one repository).

from git.

derrickstolee avatar derrickstolee commented on September 23, 2024

Sketch of the functional change I am proposing:

That would be the backwards-compatible fix. The other approach would be to change behavior by attempting all repos and returning success only if every repo succeeded. But Git doesn't typically do backwards-incompatible things. Who knows who depends on this early termination behavior?

Please also update the background maintenance schedule to include --stop-on-error on its use of for-each-repo to auto-heal users when they reconfigure background maintenance.

from git.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.