Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log from non-ancestor lists symmetric difference - should list simple difference #286

Closed
csemrau opened this issue Jul 28, 2018 · 5 comments

Comments

@csemrau
Copy link

csemrau commented Jul 28, 2018

We are trying to get a list of commits that are part of a feature branch, but not yet part of the master branch. Using git log master..feature yields those commits, regardless of whether the master branch contains additional commits. Is it possible with simple-git?

The simple-git log command logs a commit range given by opt.from + "..." + opt.to, with 3 dots. This produces the symmetric difference, containing all commits from from not in to together with all commits from to not in from.

I expect to get a log of all commits in to that are not also in from, which you would get when giving the range with only 2 dots, opt.from + ".." + opt.to.

In the current implementation, that makes from and to interchangeable and yields unexpected results whenever from is not an ancestor of to.

As an example, take the following history:

A --- B --- C (master)
 \     \
  \     \-- D (feature)
   \    
    \-- E

The command git log master..feature lists only D, because that is the only commit that is in the history of feature and not also in the history of master. Similarly, git log master..feature lists only C, the only commit on master that's not yet in feature.

Whereas git log master...feature lists both C and D, because these two commits are not common to both (like A and B) or absent from both (like E). This is also the result of the simple-git log call with {from:'master', to:'feature'}.

@Guobacai
Copy link
Contributor

Guobacai commented May 3, 2019

This feature is useful in some cases. Is there any plan on adding this feature?

@csemrau
Copy link
Author

csemrau commented May 3, 2019

We had worked around this by not providing from and to as options, but by providing the from..to expression as an option, like this.

    // This is a hack - simpleGit will just append
    // the keys of the `options` object to the command
    // if the value is not of type string (or equal to some special keys)
    const options = {
        ...
    };
    // We therefore just construct the path-spec as a special key
    const pathSpec = `${fromHash}..${toHash}`;
    options[pathSpec] = null;
    this.git.log(options, ...);

I still think it's a bug that simple-git returns the symmetric difference instead of the simple difference. If backwards compatibility is an issue, maybe a new option symmetric with default value true could be added. To get the simple difference, one would then provide options { from: ..., to: ..., symmetric: false }.

@Guobacai
Copy link
Contributor

Guobacai commented May 3, 2019

Thanks @csemrau
It seems like adding "symmetric" is not that hard.

steveukx added a commit that referenced this issue May 3, 2019
@steveukx
Copy link
Owner

steveukx commented May 3, 2019

You can add extra command line arguments using the usual how-to-specify-options. There is now a test is test-log.js that shows how to add the options in.

If you would like to have a new custom option for setting some properties, please feel free to modify git.js accordingly and open a PR.

If you would like for this to go on the backlog for my input, please can you add a test in test-log.js that shows how you want to supply arguments to the function, and the expected command line output.

@steveukx
Copy link
Owner

steveukx commented May 8, 2019

Fixes in #352 are now in NPM as version 1.113.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants