git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/5] ff-refs: add --dry-run and --skip-worktree options

From
Michael Rappazzo <rappazzo@gmail.com>
Date
Nov 11, 2015, 02:11 UTC
Message-ID
<1447207885-10911-4-git-send-email-rappazzo@gmail.com>
In-Reply-To
<1447207885-10911-1-git-send-email-rappazzo@gmail.com>

'--dry-run' reports the updatable state of each ref without acutally updating any refs. Refs which are fast-forwardable are reported as 'WOULD-UPDATE'.

'--skip-worktrees' does not update refs which are checked out in any worktree. Branches which are fast-forwardable but checked out in a worktree are reported as 'SKIPPED'. With `--dry-run` these are reported 'WOULD-SKIP'.

Signed-off-by: Michael Rappazzo <rappazzo@gmail.com>
---
 builtin/ff-refs.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/builtin/ff-refs.c b/builtin/ff-refs.c
index f14afc5..ae68cfb 100644
--- a/builtin/ff-refs.c
+++ b/builtin/ff-refs.c
@@ -5,6 +5,8 @@
 #include "run-command.h"
 #include "worktree.h"
 
+int dry_run = 0;
+int no_wt = 0;
 struct worktree **worktrees;
 const char *padding = ".....................................................";
 
@@ -18,6 +20,7 @@ enum ff_result_type {
 	UPDATABLE,
 	REMOTE_MISSING,
 	NON_FAST_FORWARD,
+	SKIPPED,
 	UNABLE_TO_UPDATE
 };
 
@@ -48,11 +51,13 @@ static const char *result_type_str(enum ff_result_type result_type)
 	case UP_TO_DATE:
 		return _("UP-TO-DATE");
 	case UPDATABLE:
-		return _("WOULD-UPDATE");
+		return dry_run ? _("WOULD-UPDATE") : _("UPDATED");
 	case REMOTE_MISSING:
 		return _("REMOTE-MISSING");
 	case NON_FAST_FORWARD:
 		return _("NON-FAST-FORWARD");
+	case SKIPPED:
+		return dry_run ? _("WOULD-SKIP") : _("SKIPPED");
 	default:
 		return _("UNABLE-TO-UPDATE");
 	}
@@ -135,7 +140,7 @@ static void process_refs(struct ff_ref_data *data)
 
 		printf("     %s -> %s%*.*s",
 			details->branch->name, details->shortened_upstream, padLen, padLen, padding);
-		if (details->result_type == UPDATABLE)
+		if (!dry_run && details->result_type == UPDATABLE)
 			do_ref_update(data, details);
 
 		printf("[%s]\n", result_type_str(details->result_type));
@@ -208,6 +213,9 @@ static int analize_refs(const char *refname,
 			else if (!in_merge_bases(details->branch_commit, details->upstream_commit))
 				details->result_type = NON_FAST_FORWARD;
 
+			else if (no_wt && details->wt)
+				details->result_type = SKIPPED;
+
 			else
 				details->result_type = UPDATABLE;
 		}
@@ -233,6 +241,9 @@ int cmd_ff_refs(int argc, const char **argv, const char *prefix)
 	int ret = 0;
 
 	struct option options[] = {
+		OPT_BOOL(0, "dry-run", &dry_run, N_("show what would be fast-forwarded")),
+		OPT_BOOL(0, "skip-worktrees", &no_wt,
+				N_("skip refs checked out in any worktree")),
 		OPT_END()
 	};
 
-- 
2.6.2
Previous: Michael RappazzoNext: Michael Rappazzo
Message 4 of 13 in “ff-refs: builtin command to fast-forward local refs”
  1. 0/5 ff-refs: builtin command to fast-forward local refsMichael Rappazzo, Nov 11, 2015
  2. 1/5 ff-refs: builtin cmd to check and fast forward local refs to their upstreamMichael Rappazzo, Nov 11, 2015
  3. 2/5 ff-refs: update each updatable refMichael Rappazzo, Nov 11, 2015
  4. 3/5 ff-refs: add --dry-run and --skip-worktree optionsMichael Rappazzo, Nov 11, 2015
  5. 4/5 ff-refs: Add documentationMichael Rappazzo, Nov 11, 2015
  6. 5/5 ff-refs: Add testsMichael Rappazzo, Nov 11, 2015
  7. Michael J GruberNov 11, 2015
  8. Mike RappazzoNov 11, 2015
  9. Michael J GruberNov 17, 2015
  10. Mike RappazzoNov 17, 2015
  11. Johannes SchindelinNov 18, 2015
  12. Jeff KingNov 24, 2015
  13. Junio C HamanoDec 1, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.