git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] git-merge -s theirs
@ 2008-07-20 10:21 Nanako Shiraishi
  2008-07-20 21:22 ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Nanako Shiraishi @ 2008-07-20 10:21 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano

Sometimes people wonder why "-s ours" strategy exists but "-s theirs" does
not.  The reason was explained on the mailing list recently:

  Quoting Junio C Hamano <gitster@pobox.com>:

  > One big problem "-s theirs" has, compared to the "reset to origin,
  > discarding or setting aside the failed history" is that your 'master'
  > history that your further development is based on will keep your failed
  > crap in it forever if you did "-s theirs".  Hopefully you will become a
  > better programmer over time, and you may eventually have something worth
  > sharing with the world near the tip of your master branch.  When that
  > happens, however, you _cannot_ offer your master branch to be pulled by
  > the upstream, as the wider world will not be interested in your earlier
  > mistakes at all.

This patch steals much code from "git-merge-resolve" to add "theirs"
strategy.  Its purpose is to always fail and suggest using the preferred
command "git reset --hard the-other-commit".

Signed-off-by: Nanako Shiraishi <nanako3@lavabit.com>
---
 Makefile            |    3 ++-
 builtin-merge.c     |    1 +
 git-merge-theirs.sh |   34 ++++++++++++++++++++++++++++++++++
 3 files changed, 37 insertions(+), 1 deletions(-)
 create mode 100755 git-merge-theirs.sh

diff --git a/Makefile b/Makefile
index 2b670d7..22f699a 100644
--- a/Makefile
+++ b/Makefile
@@ -240,6 +240,7 @@ SCRIPT_SH += git-lost-found.sh
 SCRIPT_SH += git-merge-octopus.sh
 SCRIPT_SH += git-merge-one-file.sh
 SCRIPT_SH += git-merge-resolve.sh
+SCRIPT_SH += git-merge-theirs.sh
 SCRIPT_SH += git-mergetool.sh
 SCRIPT_SH += git-parse-remote.sh
 SCRIPT_SH += git-pull.sh
@@ -1433,7 +1434,7 @@ check-docs::
 	do \
 		case "$$v" in \
 		git-merge-octopus | git-merge-ours | git-merge-recursive | \
-		git-merge-resolve | git-merge-subtree | \
+		git-merge-resolve | git-merge-subtree | git-merge-theirs | \
 		git-fsck-objects | git-init-db | \
 		git-?*--?* ) continue ;; \
 		esac ; \
diff --git a/builtin-merge.c b/builtin-merge.c
index edc6016..8ed815b 100644
--- a/builtin-merge.c
+++ b/builtin-merge.c
@@ -55,6 +55,7 @@ static struct strategy all_strategy[] = {
 	{ "octopus",    DEFAULT_OCTOPUS },
 	{ "resolve",    0 },
 	{ "ours",       NO_FAST_FORWARD | NO_TRIVIAL },
+	{ "theirs",     NO_FAST_FORWARD | NO_TRIVIAL },
 	{ "subtree",    NO_FAST_FORWARD | NO_TRIVIAL },
 };
 
diff --git a/git-merge-theirs.sh b/git-merge-theirs.sh
new file mode 100755
index 0000000..e228d2b
--- /dev/null
+++ b/git-merge-theirs.sh
@@ -0,0 +1,34 @@
+#!/bin/sh
+
+# The first parameters up to -- are merge bases; the rest are heads.
+bases= head= remotes= sep_seen=
+for arg
+do
+	case ",$sep_seen,$head,$arg," in
+	*,--,)
+		sep_seen=yes
+		;;
+	,yes,,*)
+		head=$arg
+		;;
+	,yes,*)
+		remotes="$remotes$arg "
+		;;
+	*)
+		bases="$bases$arg "
+		;;
+	esac
+done
+
+# Give up if we are given two or more remotes -- not handling octopus.
+case "$remotes" in
+?*' '?*)
+	exit 2 ;;
+esac
+
+echo "If you wanted to say the other history is better than your history," 
+echo "use 'git reset --hard $remotes' instead." 
+echo "If you want to keep a record of your failure, you can create a" 
+echo "new branch from the current HEAD before running the reset command." 
+
+exit 2
-- 
1.5.6.3

-- 
Nanako Shiraishi
http://ivory.ap.teacup.com/nanako3/

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

end of thread, other threads:[~2008-07-28  9:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-20 10:21 [PATCH] git-merge -s theirs Nanako Shiraishi
2008-07-20 21:22 ` Junio C Hamano
2008-07-28  9:18   ` Re* " Junio C Hamano

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).