git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [WIP]: make merge nicer to the user
@ 2022-03-27 15:41 Guillaume Cogoni
  2022-04-12 19:15 ` [PATCH 0/1] Be nicer to the user on tracked/untracked merge conflicts Jonathan
  0 siblings, 1 reply; 27+ messages in thread
From: Guillaume Cogoni @ 2022-03-27 15:41 UTC (permalink / raw)
  To: git; +Cc: Matthieu.Moy, git.jonathan.bressat, guillaume.cogoni

Hi,
We were working on a patch to make merge nicer to the user on
tracked/untracked merge conflicts.
You can see that idea on this page:
https://git.wiki.kernel.org/index.php/SmallProjectsIdeas

When merging a commit which has tracked files with the same name as local
untracked files, Git refuses to proceed.
We want to change this behaviour. The idea is to check if the untracked and
the tracked file has the same content, so we can overwrite it.


Examples of use cases where it can be interesting:
The scenarios are the following:

A team member is modifying the templates for a website we are working on.
They are adding some images to the images directory (but forgets to add
them under source control).
They are sending the images by mail, later, to me.
I'm adding the images under the source control and pushing them to
GitHub together with other changes
They cannot pull updates from GitHub because Git doesn't want to
overwrite their files.
Source : https://stackoverflow.com/questions/1125968/how-do-i-force-git-pull-to-overwrite-local-files

When using rsync to get files from a distant directory, but then those
files are pushed on a repo from the distant directory, you don't want to
reset the change when you just need to pull the repo because files are
the same.


The following parts is our test file:

diff --git a/t/t7615-merge-conflict.sh b/t/t7615-merge-conflict.sh
new file mode 100644
index 0000000000..4d89fe99ed
--- /dev/null
+++ b/t/t7615-merge-conflict.sh
@@ -0,0 +1,47 @@
+#!/bin/sh
+#
+# Copyright (c) 2022 Cogoni Guillaume and Bressat Jonathan
+#
+test_description='merge conflitct'
+. ./test-lib.sh
+
+test_expect_success '[FAST_FORWARD] merge conflict when untracked
file and tracked file have the same name and content' '
+ echo content >readme.md &&
+ test_commit "README" readme.md &&
+ git branch B &&
+ git checkout -b A &&
+ echo content >file &&
+ test_commit "tracked_file" file &&
+ git switch B &&
+ echo content >file &&
+ test_merge merge A
+'
+
+test_expect_success '[MERGE] merge conflict when untracked file and
tracked file have the same name and content' '
+ echo content >readme.md &&
+ test_commit "README" readme.md &&
+ git branch A &&
+ git checkout -b B &&
+ echo content1 >file1 &&
+ test_commit "B_tracked_file" file1 &&
+ git checkout A &&
+ echo content2 >file2 &&
+ test_commit "A_tracked_file" file2 &&
+ git switch B &&
+ echo content2 >file2 &&
+ test_merge merge A
+'
+
+test_expect_thatfailure 'merge conflict when untracked file and tracked
file have not the same content but the same name' '
+ echo content >readme.md &&
+ test_commit "README" readme.md &&
+ git branch B &&
+ git checkout -b A &&
+ echo content1 >file &&
+ test_commit "tracked_file" file &&
+ git switch B &&
+ echo content2 >file &&
+ test_merge merge A
+'
+
+test_done
Those tests must have assert in the end but it's just to explain our idea.

Our research lead us to these functions:

verify_absent_1() from /unpack-trees.c seems to be called for all files
and it check if a file from the merged branch exists in the current
branch in regard of the name and the path (In our test above, if a file
from the branch A exist in the branch B.). Then call check_ok_to_remove()
from /unpack-trees.c when an untracked file with the same name than a
tracked file on the merged branch is spotted.

static int verify_absent_1(const struct cache_entry *ce,
enum unpack_trees_error_types error_type,
enum absent_checking_type absent_type,
struct unpack_trees_options *o);

static int check_ok_to_remove(const char *name, int len, int dtype,
const struct cache_entry *ce, struct stat *st,
enum unpack_trees_error_types error_type,
enum absent_checking_type absent_type,
struct unpack_trees_options *o);


We think that a good way to solve this problem is to check the hash
of the tracked and untracked file in check_ok_to_remove and then if
they are similar we can
overwrite it (return 0). The hash is in ce->object_id.
In fact, it's more efficient than decompress the file and check
the content.

Do you think, we are going in the good way, and is it a good idea ?

thanks for your help and review.

Guillaume Cogoni and
Jonathan Bressat

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

end of thread, other threads:[~2022-06-10 12:59 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-27 15:41 [WIP]: make merge nicer to the user Guillaume Cogoni
2022-04-12 19:15 ` [PATCH 0/1] Be nicer to the user on tracked/untracked merge conflicts Jonathan
2022-04-12 19:15   ` [PATCH 1/1] Merge with untracked file that are the same without failure and test Jonathan
2022-04-12 19:21     ` Ævar Arnfjörð Bjarmason
2022-04-13 18:18     ` Junio C Hamano
2022-04-25 20:27       ` [PATCH v1 0/2] Be nicer to the user on tracked/untracked merge conflicts Jonathan
2022-04-25 20:27         ` [PATCH v1 1/2] t7615: test how merge behave when there is untracked file Jonathan
2022-04-25 20:27         ` [PATCH v1 2/2] merge with untracked file that are the same without failure Jonathan
2022-04-25 21:16         ` [PATCH v1 0/2] Be nicer to the user on tracked/untracked merge conflicts Junio C Hamano
2022-04-25 22:28           ` Guillaume Cogoni
2022-04-25 23:10             ` Junio C Hamano
     [not found]           ` <fdd9f13d14e942f3a1572866761b9580@SAMBXP02.univ-lyon1.fr>
2022-04-26  6:38             ` Matthieu Moy
2022-04-26 16:13               ` Junio C Hamano
2022-04-28 10:33                 ` Jonathan Bressat
2022-05-27 19:55                   ` [PATCH v2 0/4] " Jonathan Bressat
2022-05-27 19:55                     ` [PATCH v2 1/4] t6436: tests how merge behave when there is untracked file with the same content Jonathan Bressat
2022-05-27 19:55                     ` [PATCH v2 2/4] merge with untracked file that are the same without failure Jonathan Bressat
2022-05-27 19:55                     ` [PATCH v2 3/4] add configuration variable corresponding to --overwrite-same-content Jonathan Bressat
2022-05-27 19:55                     ` [PATCH v2 4/4] error message now advice to use the new option Jonathan Bressat
     [not found]                     ` <dfea1d98c15047428b1a11adbc002eef@SAMBXP02.univ-lyon1.fr>
2022-06-04  9:44                       ` [PATCH v2 1/4] t6436: tests how merge behave when there is untracked file with the same content Matthieu Moy
     [not found]                     ` <be2297bdcd724c3f8abfde2d5d74fb18@SAMBXP02.univ-lyon1.fr>
2022-06-04  9:45                       ` [PATCH v2 2/4] merge with untracked file that are the same without failure Matthieu Moy
     [not found]                     ` <82beb916d9c44a069f30ec4ff261e3be@SAMBXP02.univ-lyon1.fr>
2022-06-04  9:45                       ` [PATCH v2 4/4] error message now advice to use the new option Matthieu Moy
2022-06-10 12:58                         ` Guillaume Cogoni
     [not found]                     ` <4efbe7d9c95841c691f51954670a1d9f@SAMBXP02.univ-lyon1.fr>
2022-06-04  9:49                       ` [PATCH v2 3/4] add configuration variable corresponding to --overwrite-same-content Matthieu Moy
     [not found]         ` <eca66375d8b34154856b7da303bf96d7@SAMBXP02.univ-lyon1.fr>
2022-04-26  6:48           ` [PATCH v1 1/2] t7615: test how merge behave when there is untracked file Matthieu Moy
2022-04-12 19:24   ` [PATCH 0/1] Be nicer to the user on tracked/untracked merge conflicts Ævar Arnfjörð Bjarmason
2022-04-14  8:57     ` Jonathan Bressat

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).